NullReferenceException thrown while drawing UnityEvent property of inline editor

Issue #114 resolved
Tarocco
created an issue

Hi there, I just purchased Odin and immediately ran into trouble!

I am getting this just about every editor update call when my class is being drawn as an inline editor (by placing Sirenix.OdinInspector.InlineEditorAttribute on the field) inside another editor inspector. Log file attached.

Reproduce

  1. Let classes A and B inherit MonoBehaviour
  2. Let class CoolEvent inherit UnityEvent<object, EventArgs> and place [Serializable] on its class definition
  3. Let A have a public B MyB with [InlineEditor] attribute on it
  4. Let B have a public CoolEvent MyCoolEvent
  5. Instantiate an A instance on a GameObject named AObject
  6. Instantiate a B instance on a GameObject named BObject
  7. Using the editor, assign AObject's A.MyB to BObject
  8. Open foldout for AObject's MyB
  9. Close the foldout, and then open it again

Unity 5.6.1f1

Odin 1.0.2.1

Remarks

It only seems to happen on the SECOND time (and every time after) the inline editor is expanded!

Comments (5)

  1. Tor Esa Vestergaard

    Okay, after an hour of poring through decompiled Unity source code, I've managed to locate the issue and resolve it. This was actually an internal bug in Unity, that didn't consider that an editor might be created multiple times in between EditorGUI state resets (which generally only happen when the selection changes).

    Some internal state was being cached by Unity's own UnityEventDrawer, and became invalid when the inline editor was closed and its editor instance destroyed. Next time the inline editor would be opened, and a new editor instance created, that invalid state would still be there, cached, and would cause errors when UnityEvents were being drawn.

    Odin now always checks and fixes this internal invalid state before drawing UnityEvents.

    This fix will be included in the next patch, but if having it resolved is very critical for you, you can give me your email and I'll send you an interim build with the fix included.

  2. Tarocco reporter

    Hi Esa, I'm really glad and it's awesome that you were able to reproduce and fix this almost right away!

    At the moment, it's not a complete showstopper for me but I would appreciate having an interim build with the fix if it's not inconvenient.

    My address is bun@taroc.co.

    Gotta love Unity sometimes 🙃

    Thanks for getting to this so quickly.

  3. Log in to comment