{"record":{"id":"23f45b52c9e23cf2","repo":"FyroxEngine/Fyrox","slug":"infinite-update-loop-detected-most-likely-some-of","errorCode":null,"errorMessage":"Infinite update loop detected! Most likely some of your scripts causing infinite prefab instantiation!","messagePattern":"Infinite update 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":829,"sourceCode":"                    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,\n                            &mut context,\n                            error_queue,\n                            &mut |script, context| script.on_update(context),\n                        );\n                    }\n                }\n\n                if update_loop_iteration == max_iterations - 1 {\n                    Log::warn(\n                        \"Infinite update loop detected! Most likely some of \\\n                    your scripts causing infinite prefab instantiation!\",\n                    )\n                }\n            }\n\n            // Dispatch script messages only when everything is initialized and updated. This has to\n            // be done this way, because all those methods could spawn new messages. However, if a new\n            // message is spawned directly in `on_message` the dispatcher will correctly handle it\n            // on this frame, since it will be placed in the common queue anyway.\n            scripted_scene.message_dispatcher.dispatch_messages(\n                scene,\n                scripted_scene.handle,\n                plugins,\n                resource_manager,\n                dt,\n                elapsed_time,\n                &scripted_scene.message_sender,","sourceCodeStart":811,"sourceCodeEnd":847,"githubUrl":"https://github.com/FyroxEngine/Fyrox/blob/76c91aad8eca488ce527b1af707be8b3b24ad72d/fyrox-impl/src/engine/mod.rs#L811-L847","documentation":"Engine::handle_scripts loops calling scripts' on_update to let update-time logic (e.g. newly spawned scripts needing updates) converge, bounded by max_iterations. Reaching the final iteration without convergence triggers this warning, indicating scripts likely instantiate prefabs endlessly during update.","triggerScenarios":"Scripts calling on_update handlers that spawn/instantiate new prefabs on every iteration, so the update loop never stabilizes within max_iterations.","commonSituations":"A spawn-on-update script that respawns each frame; update logic reacting to its own spawned objects' updates in a feedback cycle.","solutions":["Gate spawning/update reactions behind flags or conditions so each trigger fires once","Move continuous spawning to an explicit event or timer instead of unconditional on_update work","Profile with logging to identify which script keeps re-triggering the update pass"],"exampleFix":"// before\nfn on_update(&mut self, ctx: &mut ScriptContext) {\n    ctx.scene.instantiate(ctx.resource.clone()); // every iteration\n}\n// after\nfn on_update(&mut self, ctx: &mut ScriptContext) {\n    if self.cooldown elapsed && self.should_spawn {\n        self.should_spawn = false;\n        ctx.scene.instantiate(ctx.resource.clone());\n    }\n}","handlingStrategy":"validation","validationCode":"// ensure on_update side effects are one-shot\nif self.spawned_this_frame { return; }\nself.spawned_this_frame = true;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid unconditional prefab instantiation in on_update","Debounce spawn logic; make it event-driven","Search update handlers for scene.instantiate calls and audit them"],"tags":["scripts","prefab","infinite-loop","update"],"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"}