Gizmos are great for debug things like collisions in your game. But last night I noticed an issue with my gizmos not showing up in my scene view (despite working 5 minutes earlier). I managed to get it fixed, but the solution was surprising and taught me something new. So if you aren’t seeing gizmos anymore in your Unity project, try this.

Open the Gizmos Component in the Unity Inspector

Unity has this little quirk where gizmos don’t render in the scene view if their components is closed in the Inspector. In my current Unity project, I have my gizmos drawing from the Collision State component.

Notice there is no gizmo in the scene view and the Collision State component is closed. Simply opening the Collision State panel in the Inspector is enough to correct the problem.

Yep. That’s really all it is. Kind of an odd quirk.

Colliders Work the Same Way

Notice in the first image above I also have a circle collider attached to my Player object. In the scene view, that collider is not displaying either. And just like the the gizmos, Unity hides the collider when the component is closed in the Inspector panel. When I open the panel, it shows up was well.

The Code

If you’re interested in the code I’m using to draw the gizmos, here it is.


    public Vector2 bottomPosition = Vector2.zero;
    public Vector2 rightPosition = Vector2.zero;
    public Vector2 leftPosition = Vector2.zero;
    public float collisionRadius = 10f;
    public Color debugCollisionColor = Color.red;

void OnDrawGizmos()
    {
        Gizmos.color = debugCollisionColor;
        var positions = new Vector2[] { rightPosition, bottomPosition, leftPosition };

        foreach(var position in positions)
        {
            var pos = position;
            pos.x += transform.position.x;
            pos.y += transform.position.y;
            Gizmos.DrawWireSphere(pos, collisionRadius);
        }
    }

All public variables so you can adjust the gizmos positions and color from the Unity Inspector panel. Simple, but effective.

Conclusion

Hopefully, that corrects the problem if gizmos were missing from your Unity project. It’s a simple fix. And honestly, one I wasn’t expecting. This is a strange little quirk that I wasn’t really expecting and I’m a little surprised it’s taken me this long to come across it.

In my opinion, there’s probably a better way of handling this than just not rendering them when the component is closed. Even the option (via public boolean) to control whether the gizmo always renders would be beneficial in my opinion. To my knowledge, this doesn’t (yet) exist. I’ve also looked for Unity packages that might add this functionality, but with no luck.

Did this solution fix your issue? Or do you know how to keep gizmos rendering even when the component is closed? Let us know in the comments below.

Categories: Unity