OdinSerialize does not work when on prefab

Issue #150 closed
Former user created an issue

Unity 5.6.2f1 Odin

Simple Script like this will fail to serialize with error when attached to a prefab and changed in scene.


using UnityEngine;
using Sirenix.OdinInspector;
using Sirenix.Serialization;
using System;

public class SerializeTest : MonoBehaviour
    public string Text;


Target of type SerializeTest does not support prefab serialization!
Sirenix.OdinInspector.Editor.PropertyTree`1:RegisterPrefabValueModification(InspectorProperty, Int32, Boolean) (at C:/Users/Bjarke/Desktop/Projects/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/PropertyTree.cs:1129)
Sirenix.OdinInspector.Editor.PropertyValueEntry`2:ApplyChanges() (at C:/Users/Bjarke/Desktop/Projects/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Value Entries/PropertyValueEntry.cs:1317)
Sirenix.OdinInspector.Editor.PropertyTree:ApplyChanges() (at C:/Users/Bjarke/Desktop/Projects/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/PropertyTree.cs:278)
Sirenix.OdinInspector.Editor.InspectorUtilities:EndDrawPropertyTree(PropertyTree) (at C:/Users/Bjarke/Desktop/Projects/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Misc/InspectorUtilities.cs:235)
Sirenix.OdinInspector.Editor.PropertyTree:Draw(Boolean) (at C:/Users/Bjarke/Desktop/Projects/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/PropertyTree.cs:144)
Sirenix.OdinInspector.Editor.OdinEditor:OnInspectorGUI() (at C:/Users/Bjarke/Desktop/Projects/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/OdinEditor.cs:183)

Comments (1)

  1. Tor Esa Vestergaard

    This is not an error, but what is supposed to happen in your case.

    The attribute you have tried to use, [ShowOdinSerializedPropertiesInInspector], should only be applied when a type is actually being serialized by Odin. This error message is expected (and should indeed occur in this case) because your type is not being serialized by Odin at all, and thus does not support special prefab serialization, as the error message notes. The attribute is telling Odin that the type is specially serialized, when it is not, and so you get errors.

    Usually, you have to inherit from a class like SerializedMonoBehaviour, which implements Odin's special serialization. SerializedMonoBehaviour has the [ShowOdinSerializedPropertiesInInspector] defined, and your class will inherit it from there, so you never actually have to put it on your type except in very special cases.

    You can read more about how to use Odin's special serialization in our manual.

    We'll update the error message to be clearer about what might have gone wrong.

  2. Log in to comment