Keep gizmos the same with the object scale

Hi, i made a simple scrip for vizualizing sphere colliders, it works, but if i chage the scale of the object, the gizmo wont scale with the object, how do i make the gizmo scale with the GO like the actual sphere collider gizmo does? how do i fix this issue? thanks a lot in advance!


using UnityEngine;

[ExecuteInEditMode, RequireComponent(typeof(SphereCollider))]
public class VisualizeSphereCollider : MonoBehaviour
    [SerializeField, Tooltip("The color of the gizmo.")]
    private Color gizmoColor =;
    [SerializeField, Tooltip("Determines if the gizmo will be drawn.")]
    private bool activated = true;
    private SphereCollider sphereCollider;

    private void Update()
        sphereCollider = transform.GetComponent<SphereCollider>();

    private void OnDrawGizmos()
        if (sphereCollider != null && activated)
            gizmoColor.a = 1f;
            Gizmos.color = gizmoColor;
            Color translucentColor = gizmoColor;
            Gizmos.DrawWireSphere(, sphereCollider.radius);
            translucentColor.a = 0.3f;
            Gizmos.color = translucentColor;
            Gizmos.DrawSphere(, sphereCollider.radius);

Replace Gizmos.DrawSphere(, sphereCollider.radius) with Gizmos.DrawSphere(, sphereCollider.radius * transform.lossyScale.x)

One way is to set the “Gizmos.matrix” to your objects localToWorldMatrix, This should scale everything accordingly.

Gizmos.matrix = transform.localToWorldMatrix;