The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

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

in Engine by (307 points)

2 Answers

+1 vote
Best answer

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)
by (6,942 points)
selected by

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

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

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

0 votes

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.

by (8,550 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.