The value of prefab instance can only be changed at the first time.

Issue #255 resolved
wavebit
created an issue

hello, please check the code and screen capture.

public interface IReadOnlyProperty<T>
{
    T Value { get; }
}

public interface IProperty<T> : IReadOnlyProperty<T>
{
    new T Value { get; set; }
}
public class TestAbility
{
    [SerializeField]
    private IProperty<int> _cdTime;

    [ShowInInspector, ReadOnly]
    public int CooldownTime
    {
        get
        {
            if (_cdTime != null)
                return _cdTime.Value;
            return 0;
        }

        set { _cdTime.Value = value; } // If this line is commented then _cdTime can be changed in inspector.
    }
}

public class Test : SerializedMonoBehaviour
{
    [SerializeField]
    public TestAbility[] TestAbilities = new TestAbility[2];
}

as2.gif

Comments (2)

  1. Tor Esa Vestergaard

    Alright, figured this one out.

    Turns out, Odin's inspector system mistakenly always had inspector properties inherit the serialization backend of the parent property, causing non-serialized nested members to be mistakenly marked with the same serialization backend as their serialized root members.

    This accidentally caused prefab modifications to be registered for non-serialized members, when those members were nested in Odin-serialized root members, and so the erroneously registered prefab modification on the CooldownTime property (which is not serialized) caused the value to become "stuck" through a complex interaction that should never be able to happen, because two different serialized members cannot normally represent the "same value". This is one of the (many, many!) reasons we don't allow serialization of properties that might have custom code in their get/set accessors!

    This is fixed now, and if you're in great need of the fix, you can mail me your Odin invoice ID at tor@sirenix.net, and I will send you a build with the fix included.

  2. Log in to comment