Search Issue Tracker
Won't Fix
Votes
1
Found in
2022.2.5f1
2023.1.0b2
2023.2.0a2
Issue ID
UUM-26855
Regression
Yes
ArgumentException when UnityEditor.InspectorWindow.RedrawFromNative calls property drawer's GetHeight() outside of OnGUI
Reproduction steps:
1. Open the attached project “IMGUIRepro”
2. Open “Assets/REPRO_SCENE” scene
3. In the Hierarchy window select “Barrel” GameObject
4. Inspect the Inspector and Console window
Expected result: “Quest Control” script shows its values and there are no errors in the Console window
Actual result: “Quest Control” script doesn’t show any of its values and an error is thrown in the Console window
Reproducible with: 2022.2.0a14, 2022.2.5f1, 2023.1.0b2, 2023.2.0a2
Not reproducible with: 2020.3.44f1, 2021.3.18f1, 2022.2.0a13
Reproducible on: macOS 13.1 (Intel)
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Unity CIL Linker fails on Player build when persistent listeners have "<" and ">" in their XML attribute names
- ”Lighting data asset ‘LightingData’ is incompatible with the current Unity version…” warnings are thrown when saving Indoors (URP) and Outdoors (URP) Scenes as Scene Templates
- [iOS] The screen blinks when transitioning from custom to Unity splash screen
- [macOS] ”Ignoring depth surface load action as it is memoryless” warnings are thrown when taking Game View Snapshot
- UI Builder Inspector scrolls back up when changes on an expanded but not fully displayed Inspector tab are saved
Resolution Note:
Hello!
The given samples call functions that are only meant to be called in "OnGui" in a function that is not "OnGui" (GetHeight); this is not guaranteed to work.
This limitation can be worked-around by not using those functions in GetHeight. To achieve this, you can either use alternatives that can be called outside of OnGui or cache some results. Here is an example updated HelpBoxAttributeDrawer:
[CustomPropertyDrawer(typeof(HelpBoxAttribute))]
public class HelpBoxAttributeDrawer : DecoratorDrawer
{
float m_lastWidth;
public override float GetHeight()
{
if (attribute is not HelpBoxAttribute helpBoxAttribute)
return base.GetHeight();
return EditorStyles.helpBox.CalcHeight(new GUIContent(helpBoxAttribute.text), m_lastWidth);
}
public override void OnGUI(Rect position)
{
var helpBoxAttribute = attribute as HelpBoxAttribute;
if (helpBoxAttribute == null) return;
m_lastWidth = EditorGUIUtility.currentViewWidth;
EditorGUI.HelpBox(position, helpBoxAttribute.text, GetMessageType(helpBoxAttribute.messageType));
}
...
}
There is a separate issue that causes the inspector to not take the height of this decorator into account if it varies, such as if you resize the inspector. This is a known issue that will be fixed.
In general, please note that starting 2022.1, the recommended way to create editor UI is with UIToolkit and that it might make sense for you to migrate from IMGUI.