Godot Version
4.6.3
How do I fix this error?
I am currently trying to send the player to the main menu whenever they enter a specific area body, as a sort of ending to the came. The body, and scene, are in a 3D scene while the main menu is in a 2D scene. Whenever I switch to the other scene, I get this error
level_end.gd:12 @ _on_body_entered(): Removing a CollisionObject node during a physics callback is not allowed and will cause undesired behavior. Remove with call_deferred() instead.
I don’t know how to fix this error. I tried the method, but it just gave me an error within the editor instead. I’m unsure of what it does, or why it needs to be there. Here is the code I have.
func _on_body_entered(body: Node3D) -> void:
if body is CharacterBody3D:
get_tree().change_scene_to_file("res://Menu/main_menu.tscn")