{"record":{"id":"cc5fba7700f0c6c1","repo":"FyroxEngine/Fyrox","slug":"infinite-init-loop-detected-most-likely-some-of-y","errorCode":null,"errorMessage":"Infinite init loop detected! Most likely some of your scripts causing infinite prefab instantiation!","messagePattern":"Infinite init loop detected! Most likely some of your scripts causing infinite prefab instantiation!","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"fyrox-impl/src/engine/mod.rs","lineNumber":802,"sourceCode":"                                scripted_scene.handle,\n                                &mut context,\n                                error_queue,\n                                &mut |script, context| {\n                                    if script.initialized && !script.started {\n                                        let result = script.on_start(context);\n                                        script.started = true;\n                                        update_queue.push_back((handle, script_index));\n                                        result\n                                    } else {\n                                        Ok(())\n                                    }\n                                },\n                            );\n                        }\n                    }\n\n                    if init_loop_iteration == max_iterations - 1 {\n                        Log::warn(\n                            \"Infinite init loop detected! Most likely some of \\\n                    your scripts causing infinite prefab instantiation!\",\n                        )\n                    }\n                }\n\n                // Update all initialized and started scripts until there is something to initialize.\n                if update_queue.is_empty() {\n                    break 'update_loop;\n                } else {\n                    while let Some((handle, script_index)) = update_queue.pop_front() {\n                        context.handle = handle;\n                        context.script_index = script_index;\n\n                        process_node_script(\n                            \"on_update\",\n                            script_index,\n                            scripted_scene.handle,","sourceCodeStart":784,"sourceCodeEnd":820,"githubUrl":"https://github.com/FyroxEngine/Fyrox/blob/76c91aad8eca488ce527b1af707be8b3b24ad72d/fyrox-impl/src/engine/mod.rs#L784-L820","documentation":"Engine::handle_scripts repeatedly runs scripts' on_init within a bounded loop (max_iterations) to let newly instantiated prefabs initialize. If the loop reaches its last iteration still producing new init work, the engine concludes some script infinitely instantiates prefabs and logs this warning, breaking the potential infinite loop.","triggerScenarios":"A script's on_init / on_start spawns or instantiates prefabs whose scripts in turn instantiate more prefabs each iteration, never converging within max_iterations.","commonSituations":"A spawn script that unconditionally spawns a copy of its own prefab; recursive prefab hierarchy where each instantiation triggers another; event feedback loops during initialization.","solutions":["Make prefab instantiation conditional so it does not run again for the newly created instances","Move self-perpetuating spawning logic out of on_init into an explicit trigger (message/timer)","Log what instantiates during each iteration to find the offending script"],"exampleFix":"// before\nfn on_init(&mut self, ctx: &mut ScriptContext) {\n    ctx.scene.instantiate(ctx.resource.clone()); // spawns a script that spawns again...\n}\n// after\nfn on_init(&mut self, ctx: &mut ScriptContext) {\n    if !self.spawned {\n        self.spawned = true;\n        ctx.scene.instantiate(ctx.resource.clone());\n    }\n}","handlingStrategy":"validation","validationCode":"// guard self-spawning prefabs\nif !self.instantiated.clone_of_me {\n    self.instantiated.clone_of_me = true;\n    scene.instantiate(prefab);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never instantiate a prefab whose scripts instantiate it again unconditionally","Use one-shot flags or messages for spawn chains","Watch the engine log for 'Infinite init loop detected' and fix the offending script immediately"],"tags":["scripts","prefab","infinite-loop"],"backgroundTag":"infinite-loop-detected","analyzedSha":"76c91aad8eca488ce527b1af707be8b3b24ad72d","analyzedAt":"2026-09-10T16:04:01.633Z","contentChangedAt":"2026-09-10T16:04:01.633Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}