Hi!
I’ve got an interesting scenario here where I have a custom PropertyDrawer for a type (ActorConceptState) and I cannot, for the life of me, get the ActorConceptStatePropertyDrawer to draw in the expected area.
As seen here:
The red line in center seems to be the “property data” separator (for lack of a better term), left of that line being the “property label” and right of that line being the “property stuff.” The circle on the far right is the actual start of the custom property I’m trying to draw.
This is all the code is doing, and the “Testing” label seems to be way, way too far to the right:
InitIfNeeded() is setting up some data only, doing no layout work.
So, question is:
Has anybody gotten a custom PropertyDrawer to draw in the correct position inside a NetworkBehaviour script?
For comparison, here’s what the custom PropertyDrawer looks like inside a normal MonoBehavior:
Everything is drawing as expected (NOTE: the alignment of the “Testing” label underneath the “script” label."
Any input would be appreciated here, thanks!
Ah, the power of a fresh cup of Oolong! INSTANTLY found a workaround…
I noticed that NetworkBehaviour has a custom editor that wraps properties in a EditorGUILayout.BeginHorizontal()/EndHorizontal() call.
ULTRA HACKS:
I just checked if the serialized object is a NetworkBehaviour and do an EndHorizontal/BeginHorizontal pair to nuke the layout:
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (property.serializedObject.targetObject is NetworkBehaviour)
EditorGUILayout.EndHorizontal();
// several lines later...
if (property.serializedObject.targetObject is NetworkBehaviour)
EditorGUILayout.BeginHorizontal();
}
I’d love a better workaround (definitely not a Unity UI expert here lol) but this works for me. Hope it helps somebody 
Hi @UnkelRambo ! I feel you, dealing with custom inspector’s sometimes feels like dealing with magic, lol
The only other thing I would do there is to add a note to check it whenever you update NGO / Unity, as that code is prone to break.
Alternatively, you could try implementing the csustom inspector through UIElements isnstead of using OnGUI, but since you already did the job I don’t know if it really makes sense anymore…
1 Like