Fixing null instance when i put my "iteractable items" in an another node

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

@onready var purple_mage: CharacterBody3D = $“…/PurpleMage”

func _ready() → void:

i have this function on ready . i want to be able to put everything in an node to load level ect. but when i put my object in node i get a error msg null instance .

Do you check in _ready() if purple_mage is null? You might be trying to initialize the variable with an incorrect path.
Where is the error thrown from? Is it the line in ready you wrote or somewhere else?

zhyrin | 2023-03-22 17:36

The error is thrown at the .connect line because he cant find my hero. I think my object is set in the world before the hero . im looking at tuto about the spawning and ect but i dont understand QQ. Its prolly just a line of code or a method that i didnt see yet !

purple_mage | 2023-03-22 17:54

if spawn my object in the world it work. But i do want to be able to put my collectable item like plant and tree in a Node apart to be able to switch scene ect but when i move my object into node it seem to instanciate before the hero . i think

purple_mage | 2023-03-22 17:57