1
\$\begingroup\$

I have a parent GameObject on which several colliders have been placed. I want to maneuver several children of this GameObject around these colliders, but I can't see the colliders if I don't have the parent selected. Is there a way for me to be able to always see the gizmos, such as the outlines of colliders, that are present on the parent GameObject and its children, while only selecting one of the child GameObjects?

I might be able to figure something out through script, but I'm specifically wondering if there's a setting built into Unity that can do this. If not, any script advice would also be appreciated.

\$\endgroup\$
1
\$\begingroup\$

No built-in way of doing what you describe AFAIK.

Here's a quick-n-dirty script that will draw the parents' and all sibling's collider bounds when any child is selected:

public class Foo : MonoBehaviour
{
 
    void OnDrawGizmosSelected()
    {
     //GetComponentsInChildren also returns components on parent
        var colliders = transform.parent.GetComponentsInChildren<Collider>();
          
        Gizmos.color = Color.green;
        
        foreach(Collider col in colliders)
        {
            var points = GetBoundsPoints(col.bounds);
            DrawPoints(points);
        }        
    }

    Vector3[] GetBoundsPoints(Bounds bounds)
    {

        Vector3[] points = {
            bounds.min,
            new Vector3(bounds.max.x,bounds.min.y, bounds.min.z),
            new Vector3(bounds.min.x,bounds.max.y, bounds.min.z),
            new Vector3(bounds.min.x,bounds.min.y, bounds.max.z),
            new Vector3(bounds.max.x,bounds.max.y, bounds.min.z),
            new Vector3(bounds.min.x,bounds.max.y, bounds.max.z),
            new Vector3(bounds.max.x,bounds.min.y, bounds.max.z),
            bounds.max
        };
        return points;
    }


    void DrawPoints(Vector3[] points)
    {
        Gizmos.DrawLine(points[0], points[1]);
        Gizmos.DrawLine(points[0], points[2]);
        Gizmos.DrawLine(points[0], points[3]);
        Gizmos.DrawLine(points[1], points[4]);
        Gizmos.DrawLine(points[2], points[5]);
        Gizmos.DrawLine(points[3], points[5]);
        Gizmos.DrawLine(points[4], points[7]);
        Gizmos.DrawLine(points[5], points[7]);
        Gizmos.DrawLine(points[6], points[7]);
        Gizmos.DrawLine(points[1], points[6]);
        Gizmos.DrawLine(points[2], points[4]);
        Gizmos.DrawLine(points[3], points[6]);

    }
}
```
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.