How to queue_free() an area

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Newby
:warning: Old Version Published before Godot 3 was released.

when my enemy’s health is 0 i want the area2d to queue_free() before the sprite queue_free() so the player wont get hurt to a dead enemy

Detail a bit more how is the sequence of events you want to get (I think your issue is with the collision/overlap management).

eons | 2017-11-18 17:29

:bust_in_silhouette: Reply From: SidCoalman

Here is one way to do it:

extends WhateverNode

var disabled = false

func _on_hit_player_area():
    if !disabled():
        player.take_harm()

func kill_enemy():
    disabled = true
    queue_free()

Sorry for the bad code readability, the code block seems to not enable indentation.

Anyway, basically:

  1. Before you harm your player, check to see if this enemy is disabled.
  2. When your enemy dies, put it to disabled (a custom variable). That way, it will not do stuff you don’t want it to while you wait for it to free.

edit to look better code format

volzhs | 2017-11-17 08:08

i just want to know how to queue_free() the area2d pls

Newby | 2017-11-17 11:21

:bust_in_silhouette: Reply From: SidCoalman

Take my previous answer: using disabled = true.

Deleting the area2d through queue_free() will still cause the same theoritical problem of the enemy possibly harming your character while waiting to die.

None the less, if you must, here is how:

get_node("your_area2D").queue_free()

Thanks the disable thing work but now to collision doesnt queue free now so i need find out how to fix that other than that it works.
8

Newby | 2017-11-18 11:32