Cannot draw a task field from a custom drawer

bdg_toast

New member
So I've run into a bit of a snag when trying to draw a task field from a task with a custom drawer.

Background: we have type X which the base type we use for all of our boss attacks, this has a custom drawer that handles some conditional inspector drawing logic. I've added a field "OtherTask", also of type X, and am attempting to draw the field via FieldInspector.DrawField, which calls the custom drawer for type X.

Predictably, this causes a stack overflow.

I suspect there's a good chance FieldInspector.DrawField is the wrong thing to use here, but I'm not aware of any public methods that do what I need. Even if I don't want to draw the same type or a task type that doesn't have a custom drawer, FieldInspector.DrawField doesn't seem to handle task references.

Is there an accessible method for drawing a task reference from a custom drawer? I'm sure there's something simple I've missed :)
 
What does your drawer look like? What is the stack overflow? FieldInspector.DrawField is the correct method to use for drawing any field type.
 
The stack overflow is the inspector recursively drawing the custom drawer.

It looks almost exactly like so:
C#:
[CustomObjectDrawer(typeof(BossAttackBase))]
public class BossAttackBaseDrawer : ObjectDrawer
{
    public override void OnGUI(GUIContent label)
    {
        var attack = task as BossAttackBase;
        attack.DoMoveToStartPosition = EditorGUILayout.Toggle(
            "Do Move to Start Position",
            attack.DoMoveToStartPosition);

        if (attack.ShouldMoveToStartPosition(out var pos))
        {
            ...
        }

        // field info for WaitFor
        var waitForField = attack.GetType().GetField("WaitFor");
        attack.WaitFor = (BossAttackBase)FieldInspector.DrawField(
            attack,
            new GUIContent("Wait For"),
            waitForField,
            attack.WaitFor);
    }
}

The declaration of WaitFor looks like so:
C#:
[ToolTip("...")]
public BossAttackBase WaitFor;

DrawField invokes BossAttackBaseDrawer.OnGUI recursively, causing the editor to crash.

I thought changing the type of WaitFor to Action might side step the issue, but then DrawField doesn't draw anything at all.
 
The first thing that the DrawField does is check if there is an object drawer for that task/field. If you call ObjectDrawer GetObjectDrawer(attack, waitForField) does it return a value? I think that it's here where the recursion is coming from.
 
Top