Hi , i am trying to save 2 different classes to one json file . I made a new class which includes other 2 class and i am trying to write that file to json . When i compile it its not giving me any errors but test.json file is empty
json utility is usually quite limited…
Could try newtonsoft json for better features.
*its hard to find correct page for it but usually i install it with add package by name…
https://docs.unity3d.com/Packages/com.unity.nuget.newtonsoft-json@3.0/manual/index.html
It looks like your SaveData class is not marked as Serializable. It has to be when you want it to be serialized. Though it’s hard to tell because you didn’t post your code. Never post code through a screenshot. Post the actual code in a code section as preformatted text.
// Just like this
Some code
...
ps: Note that you create your data subdirectory after you called your “test” method. So when you ship your game to an actual user, the first save would fail because the folder does not exist. Just a minor detail, but something you should keep in mind / fix.
nothing has chanced . Thanks for the test() tip
when i try this way i am getting this error
JsonSerializationException: Self referencing loop detected for property ‘gameObject’ with type ‘UnityEngine.GameObject’. Path ‘_miners[0]’
i have found this solution but when i apply unity just closed when game starts
JsonConvert.SerializeObject(class, Formatting.Indented,
new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Serialize
});
and when i try
JsonConvert.SerializeObject(class, Formatting.Indented,
new JsonSerializerSettings
{
PreserveReferencesHandling = PreserveReferencesHandling.Objects
});
than its giving me this error : NotSupportedException: rigidbody property has been deprecated
Okay now i have fixed the solution , its totaly my mistake . I was keep writing the codes to wrong void
