How to reference an instantiated object at runtime?

Godot Version

4.2.2

Question

In my scene I am trying to look for a specific node that gets instantiated when the scene loads using the Godots Save System tutorial. However every time the scene loads all the instantiated nodes have the generic names that Godot automatically assigns. Making the script that requires this node to not work.

The node I am trying to find is a specific door that I want to delete when specific conditions are met.

According to what I have discovered, everyone says to not rely on the names but the thing is I dont know how else to search for this specific door and using groups doesn’t seem to work either. How else can I get this node?

Can you not save the door’s name in the save file, and after load set the name back (at run time)?

When adding nodes you can use add_child’s second parameter to keep readable names, or assign .name after adding.

var new_instance := your_object.instantiate()
add_child(new_instance, true)
# or
new_instance.name = loaded_name_value

I’d handle it by having the door monitor those conditions using signals, and open itself when the right conditions are met. No need to find the door. The door just needs to know what to monitor.

so i didnt think about doing this before, i will see how this goes

ooooh i see, i will test this

so this is not gonna work because I have multiple doors that use the same script so if one of them is monitoring then all them are which is why I would like to search for a specific door instead.

It works quite well in my games with one script. You just have to understand how to set it up. But I see you found your solution.