Because Tasks all have OnDrawGizmos methods, the Unity Gizmos menu is a mess

dangoyette

New member
If you pull down the Gizmos dropdown at the top of the Scene view, it will show an entry for every class in the project that has an OnDrawGizmos method. Because the base class "Task" has a public virtual method OnDrawGizmos, it means literally every class that inherits from Task (and there are LOTS of them) results in an entry in the Gizmos dropdown. It causes the dropdown to become very slow to respond, and it makes it extremely hard to actually find anything in it.

Is it really necessary for Task to implement OnDrawGizmos, when it seems basically none of the tasks actually has a gizmo? Because Tasks is in a DLL, I can't even go in and modify this.

Do you have any recommendations on what I can do to reclaim some sanity in my Gizmos dropdown?
 
The runtime source is available so you could install that and remove the method:


I'm not sure there is a better way as Unity will automatically add it to this dropdown, even if it doesn't implement a MonoBehaviour.
 
Thanks for pointing me to the source. I basically just renamed OnDrawGizmos in the base class to "DrawGizmos", and that removed all those classes from the Gizmos dropdown, and makes the dropdown much more usable again.

I then added the DrawGizmos attribute that @OJuer mentioned, so this is the result:

Code:
    // Allow OnDrawGizmos to be called from the tasks
#if UNITY_EDITOR
    [UnityEditor.DrawGizmo(UnityEditor.GizmoType.Selected | UnityEditor.GizmoType.Active)]
#endif
    public virtual void DrawGizmos()
    {
        Gizmos.color = Color.yellow;
        if (gameObject != null)
        {
            Gizmos.DrawSphere(gameObject.transform.position, 1);
            Debug.Log($"{gameObject.name}: {gameObject.transform.position}");
        }
        else
        {
            Debug.Log($"{this.FriendlyName} has no associated game object, so no game gizmos can be drawn.");
        }

    }

This is just a dummy/poc implementation, to see if things were working. But the method does get called on all Tasks. The downside, to some, is that I don't see a way to get the class to appear in the Gizmos dropdown if you do want to enable/disable its gizmo in the editor.

In any case, I'll probably just empty out this method, and use this as-is for now. Thanks to both of you for the suggestions.
 
If you want it to appear in the gizmo drop down again, you need to implement OnDrawGizmos again. I think an empty implementation will make it appear again and you can use it to toggle gizmos, even those that are drawn with the custom attribute method. Hope this works for you
 
That's a good idea. It would be nice if there was some global (preferences-based) approach to turn the gizmos behavior on/off across the board, without requiring code changes. I don't know whether preferences can set/unset compiler options, but maybe that would be a possible approach. Toggling the option would switch between the method being named DrawGizmos or OnDragGizmos, depending on whether individual users prefer to have the option to hide/show the gizmos.

Anyway, I'm all set now. Thanks again for the help.
 
Top