- Home /
GetPropertyHeight infinite recursion on drawer
Ok I found something very strange...
here they say EditorGUI.GetPropertyHeight would call GetPropertyHeight on the drawer
https://docs.unity3d.com/ScriptReference/EditorGUI.GetPropertyHeight.html
so in this example we should get infinite recursion (the example seems wrong)
https://docs.unity3d.com/ScriptReference/SerializedProperty-isExpanded.html
I'm not sure about this. Am I wrong or should I report this?
Answer by Adam-Mechtley · Apr 20, 2017 at 10:13 AM
Hi! I wrote the isExpanded example in the documentation, and can verify it does not cause infinite recursion.
The missing piece of information here is that when you call EditorGUI.GetPropertyHeight(), it is actually getting the height from an internal "property handler" object, which are evaluated on a stack. So inside of a custom PropertyDrawer for some type, calling EditorGUI.GetPropertyHeight() on that property will return the default height for it (which in this case is a single line for the parent property and one for each child property if the parent is expanded). It's the same reason that example is able to call EditorGUI.PropertyField() inside its OnGUI() method without causing infinite recursion.
Ok, so is there a way to get the actual height? (value from the overridden method)
If you have some other property with a custom drawer, let's say a struct with a Quaternion field, if you called EditorGUI.GetPropertyHeight() inside of it, passing in the Quaternion child property, it would return the height specified by the custom drawer for the Quaternion.
Ok, sorry I was thinking it always returned the default height, now everything is clear, thank you!
It would be great if you could a small note about this in docs if you have time ;)