Check if an object has destroyed

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

I’m trying to make enemies perform certain behaviors when a player is present in the scene but when the player has queue_free(), instead of the application crashing, the enemies would change behaviors. I tried using weakref but the application just freezes when the enemy is present. Any suggestions? Here is my code:

onready var plr = get_node("/root/game/player")
var plrw = weakref(plr)

func _process(delta):
    if !plrw.get_ref(): # Has the player gone
    if plrw.get_ref():
            if get_pos().y < plr.get_pos().y:
            if get_pos().y > plr.get_pos().y:
:bust_in_silhouette: Reply From: Dava

I used Object.is_inside_tree() instead of Object.get_ref() and it now works as expected!