Hi

I have enemies that have a target position(the player) the player dies and the game crashes, obviously due to the enemies not having the player on screen anymore, i tried setting the target to null and a catch

if target == null:
	return

but it doesn't return or doesn't return fast enough and is still looking for the player, then i get the error below Invalid get index 'position' (on base: 'previously freed instance')

i do struggle with signals but i did think the idea behind signals is that when they do not couple objects and if the objects not there then they disregard and don't continue

so i set up a signal with the function below and as soon as the player dies i get the Invalid get index 'position' (on base: 'previously freed instance') again!

func _my_signal(): self.position = target.position

where am i going wrong??

Thanks to anyone that can help.

I had this issue with a tower defense project I made in Godot. I found the easiest way to work around the "previously freed instance" issue is to use a weakref (documentation) instead of a direct reference to the target node. This Godot Q&A answer shows a code snippet similar to what I used in the tower defense project.

Also, as mentioned in the Godot Q&A link, in Godot 3.1+ you can use is_instance_valid to check if the node has been freed/deleted or not.

3 years later