Non-serialized values with ShowInInspector on Odin Serialized instances dissapears on prefab instances, dissapears when any modifications are made.

Issue #290 wontfix
Bjarke Elias created an issue
public class NewBehaviourScript : SerializedMonoBehaviour
{
    public Dummy dummy;
}

public class Dummy
{
    [SerializeField]
    private string a;   // When modifications are made to this in prefab instances.
                        // The entire dummy instance gets recreated.
                        // Which means changes to the temporaryVariable gets resets as we type.

    [ShowInInspector]
    private int temporaryVariable; 
}

[OdinDrawer]
[DrawerPriority(DrawerPriorityLevel.SuperPriority)]
public class DebugThing : OdinValueDrawer<Dummy>
{
    public static System.Runtime.Serialization.ObjectIDGenerator gen = new System.Runtime.Serialization.ObjectIDGenerator();

    protected override void DrawPropertyLayout(IPropertyValueEntry<Dummy> entry, GUIContent label)
    {
        bool a;
        var id = gen.GetId(entry.WeakSmartValue ?? "", out a);

        GUILayout.Label(id.ToString());
        this.CallNextDrawer(entry, label);
        GUILayout.Space(10);
    }
}

Comments (2)

  1. Bjarke Elias reporter

    We'll revisit this issue in the future, but a fix is at this point not guaranteed. We need Tor's eyes on the issue as it's deeply tied to how prefab modifications work. Tor will join us again in 2 months time.

    For now though, just keep in mind that that is happening, and work around it. A simple fix to the problem could be would be for instance to make the temporaryVariable static, and show it through a property:

    public class NewBehaviourScript : SerializedMonoBehaviour
    {
        public Dummy dummy;
    }
    
    public class Dummy
    {
        [SerializeField]
        private string a;  
    
        private static int temporaryVariable;
    
        [ShowInInspector]
        private int TemporaryVariable
        {
            get { return temporaryVariable; }
            set { temporaryVariable = value; }
        }
    }
    
  2. Tor Esa Vestergaard

    I'm afraid this is fundamentally impossible to do with the way prefab modifications work in Unity, since changing a prefab instance's modifications immediately causes it to be deserialized with the new modifications applied, therefore losing old non-serialized values.

  3. Log in to comment