Previously (Odin 2.0.7 and lower or so), we have been drawing a shallow 2-level Odin menu tree by hand, by using OdinMenuItem.DrawMenuItem(int indent). Historically, this has worked, but since ~2.1.0+, throws a NullReferenceException.
I don’t have the old Odin source on me, but running with the 2.1.3 source, the issue happens at this line (OdinMenuItem.cs, line 812):
this.wasMouseDownEvent = eType == EventType.MouseDown && this.rect.Contains(e.mousePosition);
The issue is that e is null. Currently, e is OdinMenuTree.CurrentEvent, and that is now only set inside the OdinMenuTree.DrawMenuTree function.
While it makes sense for the menu items to require the menu tree to be drawn, this behaviour is a reversion from old versions of Unity.
For completeness sake:
- NullReferenceException when using OdinMenuItem without OdinMenuTree
Create a shallow menu tree and draw it like this:
- Issue appears in 2018.4 and 2019.1 (and probably every version of Unity ever)
- Issue appears in 2.1.3, did not appear in older versions (2.0.7 and similar)
- Windows 10
Possible fix looks like: