Hello, I am admittedly very new to Godot (starting yesterday), and I have been trying to learn Godot (mainly for fun). Ever since, I've been stuck on this error for a while (though I dont think it breaks the system I've got but I haven't tested it enough)
Here are the errors:
E 0:00:02:0523 enemy.gd:12 @ _on_entity_collision_body_entered(): Removing a CollisionObject node during a physics callback is not allowed and will cause undesired behavior. Remove with call_deferred() instead.
<C++ Source> scene/2d/collision_object_2d.cpp:98 @ _notification()
<Stack Trace> enemy.gd:12 @ _on_entity_collision_body_entered()
E 0:00:02:0523 enemy.gd:12 @ _on_entity_collision_body_entered(): This function can't be used during the in/out signal.
<C++ Error> Condition "locked" is true.
<C++ Source> scene/2d/area_2d.cpp:328 @ _clear_monitoring()
<Stack Trace> enemy.gd:12 @ _on_entity_collision_body_entered()
here is the full GD script:
extends CharacterBody2D
@export var gravity = 300.0;
func _physics_process(delta):
if not is_on_floor(): velocity.y += gravity * delta
move_and_slide()
func _on_entity_collision_body_entered(body):
if body.is_in_group("player"):
queue_free()
if position.y - 10 < body.position.y: get_tree().reload_current_scene()
the part we should be looking at is "_on_entity_collision_body_entered" function from what i can tell its the "get_tree().reload_current_scene()" call what's causing the 2 errors above
the goal of this function is to reload scene if colliding and below the enemy(well -10 of the enemy). this does happen but I get them errors and after doing some research i have no clue why it happens and would like to learn why just in case It causes problems in my future tests