codewriter-packages / Tri-Inspector

Free inspector attributes for Unity [Custom Editor, Custom Inspector, Inspector Attributes, Attribute Extensions]
MIT License
972 stars 47 forks source link

Inline (Material) Editor does not always display correctly (if new value is assigned to target value) #155

Closed MPierer closed 7 months ago

MPierer commented 7 months ago

Describe the bug

When using an attribute [InlineEditor] public Material mat; the inline editor sometimes fails to draw (empty, reported height=0) completely in case one assign a new Material to the mat variable from the Inspector.

Reason seems to be: In InlineEditorElement.cs When assigning a new value via the inspector the call to InternalEditorUtilityProxy.SetIsInspectorExpanded is omitted. This call only happens when the element is attached to a panel. See InlineEditorElement.OnAttachToPanel(). Depending on the Material's state the InlineEditor sometimes does draw. Especially if you switch to a different MonoBehaviour and back.

Possible Fix:

public override void OnGUI(Rect position)
{
...
    if (_editor == null && shouldDrawEditor && _property.Value is Object obj && obj != null)
    {
        _editor = Editor.CreateEditor(obj);
        if (obj != null && !InternalEditorUtilityProxy.GetIsInspectorExpanded(obj))
        {
             InternalEditorUtilityProxy.SetIsInspectorExpanded(obj, true);
        }
    }
... 

Desktop: Windows 10 Unity version: 2022.3.10f1 Tri Inspector version: 1.13.2