Save spawned object prefab and it's position

Announcements, support questions, and discussion for the Dialogue System.
User avatar
Tony Li
Posts: 22110
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save spawned object prefab and it's position

Post 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.
Aldurroth
Posts: 43
Joined: Wed Jul 20, 2022 8:44 pm

Re: Save spawned object prefab and it's position

Post 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.
User avatar
Tony Li
Posts: 22110
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save spawned object prefab and it's position

Post 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.
Aldurroth
Posts: 43
Joined: Wed Jul 20, 2022 8:44 pm

Re: Save spawned object prefab and it's position

Post by Aldurroth »

Amazing. Thank you for going above and beyond man.
User avatar
Tony Li
Posts: 22110
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save spawned object prefab and it's position

Post by Tony Li »

Happy to help! If you have questions about it, let me know.
Post Reply