CollisionShape2D set disabled not working

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By GreenDiggy

I’m trying to disable the collision detection when my enemy goes into a specific state.
Example:
Disabling -
func _on_Area2D_body_entered(body):
emit_signal(“Bounce”)
State = 1
if Timer.is_stopped() and BackOut.is_stopped():
AnimationPlayer.play(“ShellStill”)
Timer.start()
HitBox.set_disabled(true)
Enabling -
func _on_back_Out():
AnimationPlayer.play(“Walk”)
TimerState = false
State = 0
HitBox.set_disabled(true)

:bust_in_silhouette: Reply From: jgodfrey

Assuming HitBox is a valid reference to your CollisionShape2D, try this instead…

HitBox.set_deferred("disabled", true)

Okay thanks so much! It worked

GreenDiggy | 2020-05-10 17:52