Hi! I'm trying to set up a simple transition where, when my character walks into an enemy, it starts a combat. (On Godot 4.2.1 on Mac) Currently, my code looks like this:
func _on_enemy_body_body_entered(body):
get_tree().change_scene_to_file("res://battlefield.tscn")
With "enemy_body" being a 2DArea node, and it works when I run it in debug mode, but it still pops up the following error:
E 0:00:18:0559 overworld.gd:5 @ _on_enemy_body_body_entered(): Removing a CollisionObject node during a physics callback is not allowed and will cause undesired behavior. Remove with call_deferred() instead.
I'd like to try to do this correctly to avoid problems down the line, but I looked up the syntax for call_deferred and can't figure out how I'm supposed to incorporate it here. Whatever I try either gives me an error or just doesn't do anything. Any advice?