Why is CollisionShape2d still colliding after disabled = true?

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

I’m working on a 2d platformer and I have it set up in the usual way that when a player shoots an enemy with a projectile, or shoots something that explodes next to the enemy, the enemy dies and it’s CollisionShapes are disabled allowing the player to safely walk through the enemy.

This seems to work fine when it’s the player firing at the enemy, however when the explosion kills the enemy, the CollisionShapes remain active even though the explosion is calling the exact same Dead() function.

here’s the code for the explosion:

func _on_Explosion_body_entered(body):
if "Player" in body.name:
if "Enemy" in body.name:

And the enemy’s Dead() function:

func Dead():
is_dead = true
motion = Vector2(0,0)
$CollisionShape2D.disabled = true
$Area2D/MeleCollision.disabled = true
$Timer.stop()   #stops the enemy's shooting timer

It looks like someone is having the opposite problem here Area2D Collision disabled, can't be enabled inside of a signal · Issue #25973 · godotengine/godot · GitHub

Zylann | 2019-08-07 12:58

1 Like
:bust_in_silhouette: Reply From: Yoseph

I’m not sure but i think you can do


It works for me, thanks!

Lucas Rufino | 2019-10-29 23:48

Worked for me too, thank you!
Curious as to why would the problem happen in the first place. Is there a race condition bug within Godot for collider property?

dirtsea | 2020-08-02 13:57