Serialized UnityEvents lose the references of what was set on them

Issue #323 invalid
Former user created an issue

For Odin Version

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;

    public UnityEvent activationActions;
    public UnityEvent deactivationActions;
    public UnityEvent StartActions;
    public UnityEvent CancelActions;
    public UnityEvent CompletedActions;
    public UnityEvent FailedActions;
    public UnityEvent Unfinished;
    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