Preventing Gizmos from Scaling with Object

I am using Gizmos as a way to debug locations and hotspots in the editor, but I have noticed that my gizmos seem to scale with the object’s scale, which isn’t useful as it can mean that the visual hotspot isn’t actually the size the script is using.

So, I need to be able to scale the object for other reasons, but I need the latter gizmo (wire sphere) to NOT scale with the object.

My current code is:

private void DrawGizmo(bool selected)
    {
        var col = new Color(0.729f, 0.658f, 0.454f, 1.0f);
        col.a = selected ? 0.6f : 0.2f;
        Gizmos.color = col;
        Gizmos.matrix = transform.localToWorldMatrix;
        Gizmos.DrawCube(Vector3.zero, Vector3.one);
        col.a = selected ? 0.6f : 0.2f;
        Gizmos.color = col;
        Gizmos.DrawWireCube(Vector3.zero, Vector3.one);
        Gizmos.DrawWireSphere(Vector3.zero + radiusCenter, radius); //I need to NOT scale :smile:
    }

    public void OnDrawGizmos()
    {
        DrawGizmo(false);
    }
    public void OnDrawGizmosSelected()
    {
        DrawGizmo(true);
    }

Does anyone know how to prevent JUST line 11’s Gizmo from scaling?

It’s scaling since you set the matrix to the transform’s matrix.

You should be able to get the wireSphere in local position but not scale by just calculating it’s local position manually:

//old line 11 turns into:
Gizmos.matrix = Matrix4x4.zero;
Vector3 centerInLocal = transform.TransformPoint(radiusCenter);
Gizmos.DrawWireSphere(centerInLocal, radius);

I think that’ll work. It might be that you’ll want to save the old value of Gizmos.matrix on the top of DrawGizmo, it might no be zero that’s the correct thing to return it to.

This appears to have caused the gizmo to disappear entirely, I cannot find it anywhere in the scene.