I have several scripts attached to static and non static models of my scene. All models are instantiated at run-time (and must be instantiated at run-time because I'm procedural building the scene).

I'd like to add a BoxCollider or SphereCollider to my FBX models at runtime.

With non animated models it works simply requiring BoxCollider component from the script attached to my GameObject. BoxCollider is created of the right dimension. Something like:

public class AScript: MonoBehavior


If I do the same thing with animated models, BoxCollider are created of the wrong dimension. For example if attach the script above to penelopeFBX model of the standard asset, BoxCollider is created smaller than the mesh itself.

How can I solve this?


1 Answer 1


Have you tried using Bounds to generate the box collider? You use something like this in runtime:

   Bounds mapBounds = new Bounds (transform.position, Vector3.one);
      foreach(Transform child in this.transform) {

And then Add a BoxCollider and adjust according to those bounds.

  • \$\begingroup\$ thanks for the suggestion. I didn't know about that. I'll try your solution as soon as possible. \$\endgroup\$
    – Heisenbug
    Oct 22, 2012 at 7:47
  • \$\begingroup\$ sorry..It doesn't work. with rig datas inside the animated models, even with your method the size of mapBounds is wrong. It seems that rig controls point are included while calculating bounds. \$\endgroup\$
    – Heisenbug
    Oct 22, 2012 at 9:02
  • \$\begingroup\$ I'm sorry to hear that. Have your tried asking this in unity answers? You might have better luck asking such a specific question there. \$\endgroup\$
    – PeeC
    Oct 22, 2012 at 20:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .