Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | OnceFilo |
So I want to set my _target_node
to null when an enemy dies.
Here how I target an enemy:
in my player.gd I have:
var _target_node: Node = null
func handle_target_lock():
if Input.is_action_just_pressed("target_lock"):
if _target_node:
_target_node = null
else:
var enemies: Array = get_tree().get_nodes_in_group("Enemy")
if enemies.size() > 0:
_target_node = enemies[0]
if _target_node:
look_at(_target_node.global_transform.origin, Vector3.UP)
Problem is, when an enemy dies, _target_node
is now referencing a deleted instance.
My enemy node emits a signal died
when its hp is 0, but I don’t know how to use this information to notify my player.
How do I notify the player that the targeted enemy is dead and _target_node
should be set to null?