Errors when exiting the maze (Godot 4.2.1)

Hello,

in Godot 4.2.1 when exiting the maze I got this list of errors:

level.gd:10 @ _on_maze_body_exited(): This function can't be used during the in/out signal.
level.gd:10 @ _on_maze_body_exited(): Removing a CollisionObject node during a physics callback is not allowed and will cause undesired behavior. Remove with call_deferred() instead.
can_process: Condition "!is_inside_tree()" is true. Returning: false

When googling the error, the proposed solution was to use the call_deffered() function as one of the errors suggests. The function then looks like this:

func _on_maze_body_exited(body):
	get_tree().call_deferred("reload_current_scene")

This removed the errors but I don’t understand why I received the errors, what they mean and why using the call_deferred() function fixed them. Is it related to the newer version of Godot I’m using or did I do anything wrong?

3 Likes

Hi,

As far as I understand it, it gets flagged up in the newer versions of godot.
What I believe is happening is that the physics is still mid way trying to calculate a frame, but we’ve removed the collision objects it’s trying to access by unloading then reloading the current scene before physics has done its thing.

What call deferred will do is to carry out its given instruction at the end of the current frame cycle , by then the physics calls have been completed and the scene can be reloaded without the errors

5 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms