Search Issue Tracker
Won't Fix
Won't Fix in 2023.2.X
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
- Required SpriteMask class (ID 331) is stripped when "Strip Engine Code" is enabled
- “Maximized serialized file backup not found” error is thrown when minimizing a window in a newly opened project
- Build stack trace contains invalid lines when building with IL2CPP using scripts with delegates containing generic types in the signature
- Entities Systems window has a “Show Full Player Loop” dropdown which does nothing when clicked after enabling “Show Full Player Loop”
- Entities Hierarchy Search “Show/Hide” button’s Lens Icon is blurry when the Editor is on an external monitor
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.
Resolution Note (2023.2.X):
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.