-
Notifications
You must be signed in to change notification settings - Fork 125
BaseReferenceDrawer constant uses wrong height for a custom struct #119
Description
Issue
After generating a Reference ScriptableObject script with the SO code generator using a custom serializable struct with its own propertyDrawer, the representation of the struct has the wrong height when folded out in the editor. As far as I know, this only happens for SO References, not any of the other SO classes. It requires the "Use Constant" flag to be true. The height for the resulting representation of the property is always wrong, as the foldout icon takes up an entire line's height.
Reproduction flow
Take a simple struct, in this case called CameraView. It contains two Vector3 values, to determine the desired rotation (in Euler angles) and position of a camera. This is the struct definition:
[Serializable]
public struct CameraView {
public Vector3 cameraPosition;
public Vector3 cameraRotation;
}
Since the struct is serializable by the UnityEditor, we have a very basic PropertyDrawer, that just draws the fields as intended:
OnGUI:
EditorGUI.PropertyField(position, property, label, true);
And GetPropertyHeight:
return EditorGUI.GetPropertyHeight(property);
After this, we generate SO Architecture code for the CameraView type, including a CameraViewReference. This allows us to create a few CameraViewVariable assets, which look fine in the editor:

(Of course, we're ignoring the developer description as that was already mentioned in a different issue.)
When we finally include this reference in a MonoBehaviour, like so:
public CameraViewReference cameraView;
But when we select "Use Constant", we are immediately presented with the foldout icon, positioned a bit strangely:

This isn't a major issue though, as it's still possible to click the rightmost edge of the foldout icon, which results in the images shown at the top of this issue.
Another issue would be the indentation of this struct, as it would be better suited using the full width underneath. However, that is not the main focus.
Potential solution
After digging around in the BaseReferenceDrawer, I found a potential solution. In GetPropertyHeight, the SupportsMultiLine bool is false for custom structs. When manually set to true for testing purposes, the height changes when the field is folded out.
Closed:

Folded out:

But as you can see, the height is still a bit strange, as it now results in a bit of unused space. Regardless, I noticed the use of the [MultiLine] attribute for classes would allow one to make use of this behaviour. However, as it stands, this is only reserved for classes, and not for structs.


