#store_var then get_var not persisting EncodedObjectAsID between game restarts

1 messages · Page 1 of 1 (latest)

unkempt knot
#

Testing persistence / save game. See screenshot for code.
F5 to run project
New button: instantiate an instance of Player
Save button: uses FileAccess.store_var to save object_id to file
Load button: successfully loads object back from file system (see print outputs on lines 20-26 in coments)
F5 to restart project
Load button: loads the file, gets the object ID, but instance_from_id returns null.

Feel like I'm missing something. How to ensure that object is persisted on file system even when I restart project?

#

And note: if I try instead to use store_var(Player, true), on load I'll get "E 0:00:04:0551 test_save_load.gd:20 @ _on_button_load_pressed(): Condition "!p_allow_objects" is true. Returning: ERR_UNAUTHORIZED
<C++ Source> core/io/marshalls.cpp:717 @ decode_variant()
<Stack Trace> test_save_load.gd:20 @ _on_button_load_pressed()
"

#

E 0:00:04:0551 test_save_load.gd:20 @ _on_button_load_pressed(): Error when trying to encode Variant.
<C++ Error> Condition "err != OK" is true. Returning: Variant()
<C++ Source> core/io/file_access.cpp:372 @ get_var()
<Stack Trace> test_save_load.gd:20 @ _on_button_load_pressed()

oblique compass
#

You can't expect object Ids to be the same between runs. You need to store data, not an object reference