Question about Autoloads

Godot Version

4.4

Question

I have a Singleton PlayerInventory script, which holds an array Equipment = Array[Item] of some custom Item objects. When I move between Scenes however, I see the Equipment array automatically queue_free()s all the objects in the array, making them inaccessible.

Is this supposed to happen with objects in Autoloads, or am I screwing something up? And if so, is there a way to prevent those custom Item objects from being freed?

I do kind of have a solution - my Items get their data from an ItemResource resource, and I know I can transfer the equipment data between scenes if the Equipment is instead made to be an Array[ItemResource]. Then I could theoretically use that data to instantiate everything as I need.

However, this will complicate a LOT of things and require me to refactor a huge portion of my project. Before I do all that, I just wanted to do my due diligence and check - can I carry my array of custom objects across scenes with an Autoload? Or is my only path forward slogging through that big refactor? Any tips would be really appreciated :folded_hands:

If your Items are Nodes inside the current scene then change_scene_to_file/packed will delete them. You must either store your Items as children of the autoload or as Resources like you describe.

They aren’t exactly Nodes in the scene tree, I just have

var Equipment: Array[Item]= [null, null, null, null, null]

as a variable in my PlayerInventory autoload script, which I fill & reference elsewhere as I add/remove items. I currently just populate this array with instantiated() nodes to make them full objects, but never add_child() until they’re needed. (Maybe that’s still what you meant)

store your Items as children of the autoload

So i guess I could have this array essentially be Equipment.get_children(), instead?