Skip to content

Commit 6825230

Browse files
arttu-peltonenEvergreen
authored andcommitted
Fix URP & HDRP material UI leaking LabelWidth state
Fix https://jira.unity3d.com/browse/UUM-66215 where the layout of elements in DOTS Entity Baking Preview panel changes depending on if Material foldout UI is expanded or not. When the material foldout GUI is expanded on URP or HDRP, it affects other UI drawn afterwards because the UI logic modified persistent `EditorGUIUtility.labelWidth` value and didn't restore it properly after drawing its widgets. This PR fixes that by resetting the value to 0 after drawing the material options. The fix is made separately on CoreRP (used by URP Material Editor) and HDRP because the UI has separate implementations. Note: we are simply setting the labelWidth to 0 instead of restoring whatever value it was before, because 0 is a special value that cannot be retrieved by using the property getter of `EditorGUIUtility.labelWidth` - if the internal value is 0, it will return some predetermined values instead (see [implementation](https://github.cds.internal.unity3d.com/unity/unity/blob/trunk/Editor/Mono/EditorGUIUtility.cs#L1367-L1379)). Therefore we must make the assumption that 0 is the correct value to be restored in this case.
1 parent b67f093 commit 6825230

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

Packages/com.unity.render-pipelines.core/Editor/Material/MaterialHeaderScopeList.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ public void DrawHeaders(MaterialEditor materialEditor, Material material)
6969

7070
EditorGUILayout.Space();
7171
}
72+
73+
// Reset label width back to the default of 0 (fix UUM-66215)
74+
// NOTE: Because of how EditorGUIUtility.labelWidth works, when the internal value is 0,
75+
// we cannot read that value back from the property getter. So we just set it to 0 here.
76+
EditorGUIUtility.labelWidth = 0;
7277
}
7378
}
7479
}

Packages/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/MaterialUIBlockList.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ public void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
7171
Debug.LogException(e);
7272
}
7373
}
74+
75+
// Reset label width back to the default of 0 (fix UUM-66215)
76+
// NOTE: Because of how EditorGUIUtility.labelWidth works, when the internal value is 0,
77+
// we cannot read that value back from the property getter. So we just set it to 0 here.
78+
EditorGUIUtility.labelWidth = 0;
7479
}
7580

7681
/// <summary>

0 commit comments

Comments
 (0)