Closed Draco18s closed 3 months ago
This is an issue on Unity's end, not with this library. Unity should be providing serializers for their types as part of the official package, but they don't for whatever baffling reason. You should use this: https://github.com/applejag/Newtonsoft.Json-for-Unity.Converters
Hey thanks. I had no idea that package existed. Gave it a try and yeah, it works for my purposes. I have no idea why what it does differently worked for my situation, but it does.
Newtonsoft's serializer--the one shipped via the Unity package manager--cannot serialize Unity structs without manual JsonConverters being written for every single one of them.
Usually I only have to deal with things like
Vector3
which fail to deserialize becausemagnitude is read only
.But get a load of this gem:
JsonSerializationException: Self referencing loop detected for property 'linear' with type 'UnityEngine.Color'. Path 'MainPlayer.Faction.Color.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear.linear'.
And of course this only generates
JsonSerializationException: Self referencing loop detected for property 'linear' with type 'UnityEngine.Color'. Path ''.
With an empty path. Thanks Unity.In theory I can set
settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
, which will serialize the color standalone, but the larger project ends up crashing so hard there's no crash reporter (that is: I need the cyclic references to error so I can fix them).