0 votes

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:
in Engine by (116 points)

1 Answer

0 votes

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

by (116 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.