The Path Enemies Are Not Fully Deleted If Shot

In the project, Path Enemies will die if they hit the end of the path because their code calls queue_free() when hitting the progress ratio.

Unfortunately, because getting shot does not complete the path, the die() triggered from the enemy scene will only free the enemy instance within the Path Enemy from queue.

This leaves behind a bunch of stray Path2Ds and PathFollow2Ds from the ones that get shot.

To fix this, just connect the died() signal from the enemy instance in the PathEnemy hierarchy to the Path2D node and call queue_free() from there.

In the node inspector for the enemy scene inside of the path_enemy scene:
image

In the script for the path_enemy:
image

Now when the enemies die, the path dies. Hope this helps!

2 Likes

Ah, nice spot. I Didnt think to even check if the parent was still there.

Cheers for that :+1:

1 Like

No problem. Happy it helps! Also at least it’s proof that all of the GDTV courses are working that I can even catch stuff like this now. Haha. :sunglasses:

1 Like

I think what you did is correct, and the Path2D should be deleted when we shoot the enemy.


But if you did everything like in the lessons, the PathEnemy will be deleted when the timer hit 0, even if you shoot an enemy.

This is because when you shoot an enemy it will die, but the Path2D & PathFollow2D will still do its things, so the process won’t stop and eventually the progress_ratio will be at 0, and the queue_free() will be called for the path_enemy scene’s main node (so it will be completly deleted).

However if you set the PathFollow2D’s Loop On it wont be deleted, because the progress ratio will never reach 0. (I already did that mystake :grinning: here: Disable the loop in PathFollow2D)

Privacy & Terms