Page 2 of 2

Re: Save spawned object prefab and it's position

Posted: Sat Feb 17, 2024 2:41 pm
by Tony Li
Hi,

If the variable to save (e.g., point_1) is a reference to a GameObject, Transform, or the like, Unity JsonUtility can't serialize it into a text string. The save system's JsonDataSerializer component uses JsonUtility.

Instead, if you can give point_1's GameObject a unique name, you can save the name. In ApplyData(), you can find the GameObject again by its name.

Alternatively, you could save some other info that uniquely identifies that GameObject so you can find it later when restoring the saved game. This is a little more complex, so if you can use unique GameObject names it will be simpler to code up.

Re: Save spawned object prefab and it's position

Posted: Tue Feb 20, 2024 4:39 pm
by Aldurroth
Changing the name just seems to erase it when I try to save. Each new Instantiated object just labels it as "name"(Clone). I guess unity stopped doing clone numbers or something. I guess the system dose not keep track of name changes by default then.

Re: Save spawned object prefab and it's position

Posted: Tue Feb 20, 2024 9:10 pm
by Tony Li
Hi,

You may need to set the Save System's Frames To Wait Before Apply Data to 1 if you haven't already. Here's an example scene:

StickyNoteExample_2024-02-20.unitypackage

See the "---README---" GameObject for notes on the scene as well as the comments in the scripts.

Re: Save spawned object prefab and it's position

Posted: Wed Feb 21, 2024 2:29 am
by Aldurroth
Amazing. Thank you for going above and beyond man.

Re: Save spawned object prefab and it's position

Posted: Wed Feb 21, 2024 8:18 am
by Tony Li
Happy to help! If you have questions about it, let me know.