Can I use Odin's serialization without inheriting from SerializedMonoBehaviour etc.?

If you wish to add Odin serialization support to one of your existing UnityEngine.Object type classes, without inheriting from SerializedMonoBehaviour etc. You can do so easily so. It's explained in depth in our manual here: Serialize Anything.

But you can also use Odin's serialization API to serialize and deserialize your data into and from a simple byte array.

Usually, you would use the SerializationUtility class, which wraps the serialization system and handles all the boilerplate code involved. Some example code might be as follows:

// Take a class with some random garbage string data, random numbers, unity objects, and cyclic references
public class MyData
{
    public string str = new string(Enumerable.Range(0, 20).Select(i => (char)UnityEngine.Random.Range(50, 150)).ToArray());
    public List<float> numbers = new List<float>(Enumerable.Range(0, 10).Select(i => UnityEngine.Random.Range(0f, 100f)));
    public GameObject unityObjectReference = UnityEngine.Object.FindObjectOfType<UnityEngine.GameObject>();
    public MyData reference;
}

// Somewhere, a method to serialize data to json might look something like this
private void SerializeData()
{
    // Save to Assets folder
    string path = Application.dataPath + "/data.json";

    // Initialize some data
    var originalData = new MyData();
    originalData.reference = new MyData();
    originalData.reference.reference = originalData;

    // Unity should be allowed to handle serialization and deserialization of its own weird objects.
    // So if your data-graph contains UnityEngine.Object types, you will need to provide Odin with 
    // a list of UnityEngine.Object which it will then use as an external reference resolver.
    List<UnityEngine.Object> unityObjectReferences = new List<UnityEngine.Object>();

    //DataFormat dataFormat = DataFormat.Binary;
    DataFormat dataFormat = DataFormat.JSON;
    //DataFormat dataFormat = DataFormat.Nodes;

    // Serialization
    {
        var bytes = SerializationUtility.SerializeValue(originalData, dataFormat, out unityObjectReferences);
        File.WriteAllBytes(path, bytes);

        // If you want the json string, use UTF8 encoding
        // var jsonString = System.Text.Encoding.UTF8.GetString(bytes);
    }

    // Deserialization
    {
        var bytes = File.ReadAllBytes(path);

        // If you have a string to deserialize, get the bytes using UTF8 encoding
        // var bytes = System.Text.Encoding.UTF8.GetBytes(jsonString);

        var data = SerializationUtility.DeserializeValue<MyData>(bytes, dataFormat, unityObjectReferences);
    }
}

This code results in a json file looking something like this:

{
    "$id": 0,
    "$type": "0|Test.SomeMonoBehaviour+MyData, Assembly-CSharp",
    "str": "^|u\u008c\u0093l;L]\u008bS7\u0095\u00902?t74\u0090",
    "numbers": {
        "$id": 1,
        "$type": "1|System.Collections.Generic.List`1[[System.Single, mscorlib]], mscorlib",
        "$rlength": 10,
        "$rcontent": [
            43.22428,
            24.3502026,
            97.77544,
            84.8498459,
            29.8572845,
            39.2639351,
            3.33006382,
            94.28071,
            20.3551655,
            38.9832077
        ]
    },
    "unityObjectReference": $eref:0,
    "reference": {
        "$id": 2,
        "$type": 0,
        "str": "Ii6Zet3Jb\u008c\u0084\u0085EQv\u0093j{[F",
        "numbers": {
            "$id": 3,
            "$type": 1,
            "$rlength": 10,
            "$rcontent": [
                19.2796345,
                64.121666,
                37.64587,
                21.2250347,
                73.44544,
                40.8876953,
                73.282135,
                50.79189,
                59.83468,
                99.1492844
            ]
        },
        "unityObjectReference": $eref:0,
        "reference": $iref:0
    }
}

As you can see, Odin's json format keeps a bunch of metadata in special $-prepended entries. As such, this is not strictly completely correct json, but these are necessary to be able to fully reconstruct the data to the specifications of Odin's serialization system.

Whether or not you should use this, depends on your exact use-case though. If you just want to save some very simple data to json, we would advice you to use Unity's own JsonUtility class - it's a lot faster than Odin's json serialization, which is comparatively slow. (Odin's binary format is very fast and highly optimized - the json, not so much. We just never took the time to do it, as it wasn't a high priority. Json is never used in Odin, by default.)

Can I use Odin for its editors only, without using the serialization? Can I use Odin for its editors only, without using the serialization?
Can I use Odin to make inspectors for my own asset store plugins? Can I use Odin to make inspectors for my own asset store plugins?
Can I use Odin Inspector to create custom editor windows? Can I use Odin Inspector to create custom editor windows?
Does the serialization support Windows Store and UWP? Does the serialization support Windows Store and UWP?
How do I contact Sirenix to report bugs, suggest features, or in general? How do I contact Sirenix to report bugs, suggest features, or in general?
Does Odin support serialization of Unity object references? Does Odin support serialization of Unity object references?
Does Odin support interfaces? Does Odin support interfaces?
How can I add an image to the inspector? How can I add an image to the inspector?
Why isn’t Odin drawing the inspector for my script? Why isn’t Odin drawing the inspector for my script?
Why is Odin not serializing or showing my field or property? Why is Odin not serializing or showing my field or property?
How will Odin handle existing editors? How will Odin handle existing editors?
How can I make a list show one item per page? How can I make a list show one item per page?
Does Odin support cross scene references? Does Odin support cross scene references?
Can I disable or hide an inspector property in play mode, or vice versa? Can I disable or hide an inspector property in play mode, or vice versa?
Which platforms are supported by Odin? Which platforms are supported by Odin?
How easy is Odin to uninstall? How easy is Odin to uninstall?
How will Odin affect performance in the inspector? How will Odin affect performance in the inspector?
How can I make my data in Odin Editor Windows persistent? How can I make my data in Odin Editor Windows persistent?
Unity crashed, could this have something to do with Odin? Unity crashed, could this have something to do with Odin?
How can I show static fields and properties in the inspector? How can I show static fields and properties in the inspector?
How fast is Odin's Serialization system? How fast is Odin's Serialization system?
How stable/reliable is Odin's serialization system? Can I safely use it in my project? How stable/reliable is Odin's serialization system? Can I safely use it in my project?
Is it possible to customize how the dictionary drawer draw its key-type using attributes? Is it possible to customize how the dictionary drawer draw its key-type using attributes?
How can I make an attribute that lets you drag elements unto a member to set its value? How can I make an attribute that lets you drag elements unto a member to set its value?
Why are my values disappearing when I hit play? Why are my values disappearing when I hit play?
Can I write my own custom editor code using Odin? Can I write my own custom editor code using Odin?
Why is there a Serializable JSON Dictionary in my Odin Editor Window? Why is there a Serializable JSON Dictionary in my Odin Editor Window?
How can I rename a type without loosing data? How can I rename a type without loosing data?
Odin Assembly Import Settings Odin Assembly Import Settings
Why am I getting exceptions when Odin deserializes in player? Why am I getting exceptions when Odin deserializes in player?