storing objects into save files

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

is there a way to save objects into save files?
Like I have an array of packed scenes and I need to put them all together with a bunch of other basic variables into one save file
but just storing the array into the files only stores an ID to the objects

:bust_in_silhouette: Reply From: exuin

You can turn your objects into PackedScenes and then save them all into a scene file per the example in the docs. Alternatively, you can just save the relevant info from the objects and then re-create the objects when loading a save file.

:bust_in_silhouette: Reply From: Wakatta

So the reason that happens is due to the fact that the object as a whole is not stored but only a link to it instead.

In other languages this would be called a pointer and you may have to iterate trough your array saving each value with var2str or File.store_var and on load str2var and File.get_var

No need to create a new list either just write the values back to that array.

for val in my_array:
    index = my_array.find(val)
    my_array[index] = var2str(val)

that just turns the packedscenes into a string that shows their name, how is str2var turn them back into a packedscene/object?

zen3001 | 2021-04-01 15:01

nvm, I read the output wrong. it worked fine, thanks

zen3001 | 2021-04-01 15:14

Yeah it looks like a string but it’s actually a Resource with the nodepath to the packed scene. Glad it all worked as expected

Wakatta | 2021-04-01 15:18