Why does JsonUtility not support engine types?
So using JsonUtility.ToJson(transform)
will result in an error:
ArgumentException: JsonUtility.ToJson does not support engine types.
My question is why? Why can I serialize all self-implemented Mono Behaviours but no engine types? I cannot see any logical reason why this is explicitly forbidden. Yes it is possible using EditorJsonUtility
, but I want to be able to do this in the game.
The reason why I want this, is for example to save the initial Transform
of an object so I can reset its position/rotation/transform to its original state. Yes I can copy the variables, but I want a more general approach so any component can be stored without the need to define all variables you wish to save for every single component.
Answer by superpig · Jul 27, 2016 at 01:48 AM
It's because the engine binary actually does not contain the code needed to transfer engine types to/from JSON. We looked at adding it initially, but it would have meant that the JSON system could no longer be stripped from the engine for projects that do not use it, while also making it larger.
In practice this would mean giving everyone a ~500kb increase in binary size, whether they were using JSON or not; that's not acceptable on platforms like WebGL, and it's not nice on mobile platforms.
What about EditorJsonUtility? It's supposedly built for Unity types and allows JsonUtility functionality, but I can't find how to implement it anywhere.
hello sir, UnityEngine object serialization at runtime would be so useful for many applications, and would save a ton of development effort from re-creating the unityengine objects' variables as $$anonymous$$onobehavior classes and then loading them back in the form of unityengine objects. 0.5$$anonymous$$b doens't seem that bad... this is definitely on my wishlist.
Your answer
Follow this Question
Related Questions
Exlcude fields from JsonUtility but still serialise them? 1 Answer
UnityEvent with all derived types in listeners serialized in Inspector 0 Answers
Array of custom classes not saving to Playmode 0 Answers
Recursive JSON serialization / serialize list of custom serializable objects? 1 Answer
Enemy Spawn System Glitch 0 Answers