Every time an enemy hits a player, a signal will be given. We need to disable the player's collection so that we don't trigger the hit signal more than once.
Note: Disabling the shape of the collision area may result in an error if it occurs in the middle of the collision processing by the engine. Using set_deferred()
tells Godot to wait for the figure to be disabled until it is safe to do so.
GD script
func _on_body_entered(body): # Must be deferred as we can't change physics properties on a physics callback. $CollisionShape2D.set_deferred("disabled", true)
C#
private void OnBodyEntered(Node2D body) { // Must be deferred as we can't change physics properties on a physics callback. GetNode("CollisionShape2D").SetDeferred(CollisionShape2D.PropertyName.Disabled, true); }