Serialized UnityEvents lose the references of what was set on them

Issue #323 invalid
Former user created an issue

For Odin Version 1.0.6.5

Steps to reproduce: 1. Create a MonoBehaviour with the code below. 2. Go to Unity so that the code is compiled. 3. Add some stuff to some of the events in the inspector. 4. Go to the code and change or add a UnityEvent variable. 5. Go back to unity to recompile 6. Confusion.

For some reason some of the functions being added to the events are being lost upon recompilation. What am I doing wrong? Shouldn't variables of the same type retain the inspector references and information after a name change?

They also lose references when simply adding new variables to the code.

        public enum MTActionType { TurnOn, TurnOff };
    [TabGroup("ParentGroup", "StateEvents")]
    public bool a;
    [TabGroup("ParentGroup", "ProgressEvents")]
    public bool b;

    [TabGroup("ParentGroup/StateEvents/InnerGroup","OnActivated")] 
    public UnityEvent activationActions;
    [TabGroup("ParentGroup/StateEvents/InnerGroup","OnDeactivated")] 
    public UnityEvent deactivationActions;
    [TabGroup("ParentGroup/StateEvents/InnerGroup","OnStarted")]
    public UnityEvent StartActions;
    [TabGroup("ParentGroup/StateEvents/InnerGroup","OnCanceled")] 
    public UnityEvent CancelActions;
    [TabGroup("ParentGroup/StateEvents/InnerGroup","OnCompleted")] 
    public UnityEvent CompletedActions;
    [TabGroup("ParentGroup/StateEvents/InnerGroup","OnFailed")] 
    public UnityEvent FailedActions;
    [TabGroup("ParentGroup/ProgressEvents/InnerGroup","IsUnfinished")]
    public UnityEvent Unfinished;
    [TabGroup("ParentGroup/ProgressEvents/InnerGroup","IsFinished")]
    public UnityEvent Finished;

Comments (2)

  1. Dominic Antonelli

    I don't think Unity is set up to keep serialized references after you change the name of a variable. However, you may be able to use the FormerlySerializedAs attribute, though I'm not 100% sure if it actually works with UnityEvents.

  2. Tor Esa Vestergaard

    This issue isn't very well explained - as far as I can tell, this is all working as intended. These fields are even serialized by Unity, and not Odin. Until some reproduction steps showing a clear Odin-related error show up, I'm marking this as invalid.

  3. Log in to comment