fixed message dispatching
@@ -428,17 +428,10 @@ impl ScriptProcessor {
script.on_update(context);
});
}
- }
-
- if update_loop_iteration == max_iterations - 1 {
- Log::warn(
- "Infinite update loop detected! Most likely some of \
- your scripts causing infinite prefab instantiation!",
- )
- }
- }
- // Process messages.
+ // Dispatch messages and go to the next iteration of update loop. This is needed, because
+ // `ScriptTrait::on_message` can spawn new scripts that must be correctly updated on this
+ // frame (to prevent one-frame lag).
scripted_scene.message_dispatcher.dispatch_messages(
scene,
plugins,
@@ -447,6 +440,15 @@ impl ScriptProcessor {
elapsed_time,
&scripted_scene.message_sender,
);
+ }
+
+ if update_loop_iteration == max_iterations - 1 {
+ Log::warn(
+ "Infinite update loop detected! Most likely some of \
+ your scripts causing infinite prefab instantiation!",
+ )
+ }
+ }
// As the last step, destroy queued scripts.
let mut context = ScriptDeinitContext {
