Help, how to make this unity save and load system work?
It is a unity script. I added a group of gameObjects in the
ListOfGameObjects
. Manually called GOListToNOList()
(Worked) then called Save()
. Save() worked also, but only gave me an empty json, just a pair of brackets. Thanks5 Replies
According to the Unity documentation https://docs.unity3d.com/ScriptReference/JsonUtility.ToJson.html, it appears you are not allowed to serialize an array and presumably List<T> directly, as it tries to serialize the public fields on the List object itself, not the contents within.
You need to wrap the list in a separate serializable class or struct, which you seem to already have with
ListObjectToSave
but aren't using.
Try replacing this line in your Save method from
to
and change the type and assignment of the JsonUtility.FromJson
call in your Load method.
You might also need to add a [System.Serializable]
attribute to the ListObjectToSave
class.Omg, I guess that worked. You guys are op. You figured that out just from the documentation even if you are not into unity.... I was staring at that for like 2 hours already. Alright, cheer thanks!!
I do Unity, but I've never touched the JsonUtility class. I used to use Newtonsoft but now I use System.Text.Json
oh, wierd you're not in unity discord. And Im not familiar with those 2 json library, but might be worth studying for the next time
Oh I never realized there was an official Unity discord server