Re: Save spawned object prefab and it's position
Posted: Sat Feb 17, 2024 2:41 pm
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.
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.