Home > Software engineering >  Calculate bounds of gameobject without Mesh, Renderer or Collider
Calculate bounds of gameobject without Mesh, Renderer or Collider

Time:05-28

How to calculate the bounds of an object when it does not have Renderer, Mesh or Collider components. enter image description here

Inspector for object: enter image description here

Inspector for child object: enter image description here

CodePudding user response:

You could get all child renderers (or colliders), then unite all of them.

var renderers = gameObject.GetComponentsInChildren<Renderer>();
var bounds = renderers[0].bounds;
for (var i = 1; i < renderers.Length;   i)
    bounds.Encapsulate(renderers[i].bounds);
  • Related