FyroxEngine/Fyrox · error

Infinite init loop detected! Most likely some of your…

Error message

Infinite init loop detected! Most likely some of your scripts causing infinite prefab instantiation!

What it means

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.

Solutions

  1. Make prefab instantiation conditional so it does not run again for the newly created instances
  2. Move self-perpetuating spawning logic out of on_init into an explicit trigger (message/timer)
  3. Log what instantiates during each iteration to find the offending script

Example fix

// before
fn on_init(&mut self, ctx: &mut ScriptContext) {
    ctx.scene.instantiate(ctx.resource.clone()); // spawns a script that spawns again...
}
// after
fn on_init(&mut self, ctx: &mut ScriptContext) {
    if !self.spawned {
        self.spawned = true;
        ctx.scene.instantiate(ctx.resource.clone());
    }
}
Defensive patterns

Strategy: validation

Validate before calling

// guard self-spawning prefabs
if !self.instantiated.clone_of_me {
    self.instantiated.clone_of_me = true;
    scene.instantiate(prefab);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of FyroxEngine/Fyrox@76c91aad8e (2026-09-10). Data as JSON: /api/errors/cc5fba7700f0c6c1. Report an issue: GitHub.

Appendix: source

Thrown at fyrox-impl/src/engine/mod.rs:802

                                scripted_scene.handle,
                                &mut context,
                                error_queue,
                                &mut |script, context| {
                                    if script.initialized && !script.started {
                                        let result = script.on_start(context);
                                        script.started = true;
                                        update_queue.push_back((handle, script_index));
                                        result
                                    } else {
                                        Ok(())
                                    }
                                },
                            );
                        }
                    }

                    if init_loop_iteration == max_iterations - 1 {
                        Log::warn(
                            "Infinite init loop detected! Most likely some of \
                    your scripts causing infinite prefab instantiation!",
                        )
                    }
                }

                // Update all initialized and started scripts until there is something to initialize.
                if update_queue.is_empty() {
                    break 'update_loop;
                } else {
                    while let Some((handle, script_index)) = update_queue.pop_front() {
                        context.handle = handle;
                        context.script_index = script_index;

                        process_node_script(
                            "on_update",
                            script_index,
                            scripted_scene.handle,

View on GitHub (pinned to 76c91aad8e)