SerializedScriptableObject is not serialized after save and restart unity.

Issue #245 invalid
wavebit
created an issue

Hello, please check the comment.

[CreateAssetMenu]
public class ScriptableUnitDecProperty : SerializedScriptableObject
{
    [SerializeField] private int _value;

    public int Value { get { return _value; } set { _value = value; } }
}

[CreateAssetMenu]
public class UnitDec : SerializedScriptableObject
{
    [SerializeField] public ScriptableUnitDecProperty HealthValue;

    [SerializeField] public ScriptableUnitDecProperty MaxHealthValue;

    [ShowInInspector]
    // Changing the value by dragging mouse or typing directly, the value is not serialized though the input box shows expected value.
    public int Health { get { return HealthValue.Value; } set { HealthValue.Value = value; } }

    [ShowInInspector]
    // same as above
    public int MaxHealth { get { return MaxHealthValue.Value; } set { MaxHealthValue.Value = value; } }
}

Unity 2017.2.0f3 Win 10 x64

Comments (1)

  1. Tor Esa Vestergaard

    Let me take the previous answer back, sorry - it is vaguely relevant here, but not directly. You are changing values in one ScriptableObject by inspecting another ScriptableObject. This completely breaks the way Unity (and Odin) keeps track of dirtying assets and marking them changed, so that those changes can be saved. I recommend that you use the [InlineEditor] attribute on your HealthValue and MaxHealthValue instead, and change the values like that, so that the assets are marked dirty properly. The alternative would be to manually mark them dirty constantly, or through some other mechanism. Regardless, your particular example isn't a case that Odin can support out of the box.

    ---- (old answer)

    This is intended behaviour. Please see this FAQ answer, as well as this one, for further details.

  2. Log in to comment