OnDrawGizmo not called when editing ExternalBehaviorTree?

AIGuru

New member
Hi,

I'm using OnDrawGizmo() to dynamically changed the FriendlyName of a custom task node I made. Works perfectly fine when editing a behavior tree from a script instance in a gameobject, but doesn't work when editing a behavior tree from an ExternalBehaviorTree. Seems odd...any solution for this?


Code:
public override void OnDrawGizmos()
{

    this.FriendlyName = newname;

    base.OnDrawGizmos();

}
 
External Trees are Scriptable Objects instead of MonoBehaviours so there isn't a way to get that callback. Instead of changing the name within OnDrawGizmos you could create an object drawer that does it.

 
Hmm...Did give it a try but it's not working either.

Got issues when editing a BT having more than one instance of my node : name update changes only one instance and not necessarely the selected one. Sometimes it doesn't change anything (but the attribute value is updated correctly). Really weird behavior.

Any idea? Is ObjectDrawer .Task attribute returns instance of the active Task in inspector?

C#:
        [CustomObjectDrawer(typeof(FriendlyNameActionAttribute))]
        public class FriendlyNameActionDrawer : ObjectDrawer
        {
            public override void OnGUI(GUIContent label)
            {
                value = (EActionType)EditorGUILayout.EnumPopup("ActionType", (EActionType)value);
                Task.FriendlyName = value.ToString();

                Debug.Log(Task.FriendlyName);
                
            }
        }
        
        public class FriendlyNameActionAttribute : ObjectDrawerAttribute
        {
            public FriendlyNameActionAttribute()
            {
            }
        }
 
Is OnGUI getting called? The drawer is only executed when you have the task selected and the task inspector open so this may not be as universal of a solution as what are you going for.

Taking a step back, in what situations are you trying to change the name? If I understand the situation better I may have a better idea of how to solve it.
 
I simply want to change the name of a task based on the value of an enum attribute belonging to the task. When I change the enum attribute value, I would like to see the name of the task updated live. Ideally, it should be working when editing gameobject BehaviorTree instances and ExternalBehaviorTrees.

Does it make sense?
 
In that case object drawers should be perfect for the job. Does OnGUI get called?
 
Yes, it is. But the Task attribute isn't always the task associated with the selected task (when I've got more of one instances of that tasks in a BT). So when I changed the FriendlyName, it sometime changes the one from another task.
 
Ah, I think I know what it is. The task variable isn't always filled - I have this fixed though. If you can send me a PM with what Unity version you are using I'll send you the fixed version.
 
Got another question about the Task variable : the Owner field seems null during OnGUI(GUIContent label) of the ObjectDrawer. Anyway to get that filled as well? I would like to set Task's FriendlyName to be set to the BehaviorName of its Owner.
 
The owner of the task is normally set at runtime - in the case of external trees it will never have an owner until that tree is executed. I suppose that I could create a new property on the ObjectDrawer that points to the parent object that the task belongs to. You can then cast this object to an ExternalTree and get the name.
 
Would be perfect!

Also, can it possible to get the Rect position and SerializedProperty property parameters in the OnGUI function?

ex. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)

It would help me create more sophisticated ObjectDrawers.
 
When the inspector is drawn it uses the Layout functions so the Rect position isn't available. Also, since the task objects are not serialized by Unity there isn't a SerializedProperty.

I just thought of this but there is actually a way to get the behavior tree name within the object drawer:

Code:
var name = BehaviorDesignerWindow.instance.ActiveBehaviorSource.behaviorName;
 
Ok, I'll try this.

About task objects not being serialized, it's odd because I'm getting some issues when I modify the Task property within the ObjectDrawer : when leaving the BT view, all changes I made to the Task specific properties are gone (ex. a modification to a float variable belonging to the Task)...like if I forgot to update a serialized object. Although, it seems to be working fine for Task's NodeData Comment and Task's Name properties. I don't clearly understand what's happening. Is the Task property contains a Copy of the Task?

Form my understanding, with the current solution, only certain properties can be modified in a persistent way, others aren't. Any idea why?
 
When you make a change you'll want to ensure that you set GUI.changed to true so the tree is reserialized after you made a change. Without this there isn't a guarantee that the tree will be serialized.
 
Top