When I create a game object that has children and I need the game object to be affected by physics I put a rigid body on the game object. If I put colliders on the children of the parent game object that has a rigidbody do I then need to put a rigid body on each child with a collider? I read that all game objects with colliders must have a rigidbody for performance reasons. My question is if the parent has a ridgidbody already, is it better for performance or worse for performance if you place a rigidbody on children who have colliders? Or should I just leave the children as colliders without rigidbodies?
let me know what the best practice is for performance.
This may not completely answer your question, but I’ll let you know what I do from experimenting a little with Unity. I’ve been using Unity for a year and a half now (so I’m not an expert, but this is just from my own experience).
Lets say I have a simple square wall that I divided up into several pieces in my 3d modeling application. Then I import this wall into Unity and drag it into my scene. In general, the “parent” gameobject is simply like an empty game object under which all of my wall pieces are placed as children of the empty game object.
The parent object only has a position marker (i.e. the transform component and maybe an animation component by default), but I usually delete this as the parent object doesn’t need it (keep in mind yours might though).
In my example, I need to put colliders and rigidbodies on all of my children if I want them to hit and be hit by stuff, but I don’t need anything on the parent game object because it’s just a positional thing – it doesn’t need to collide with anything by itself (but the children wall pieces do).
I think the answer to your question is “do your children behave the way you want them to without rigidbodies?”. If your child game objects behave the way you need them to without rigidbodies, I’d say leave the rigidbody component off.
As far as I know, the more rigidbodies you have, the worse it is for performance – but if your gameobjects don’t collide without them, then add the rigidbodies to them. The rigidbody component is there to define how it should act under the physics system, in terms of gravity and mass. The collider is simply a detection mechanism that tells Unity if this object “touched” another object – the rigidbody controls what happens after the collider step has been determined.
As far as I’m aware, you’ll only need individual rigidbodies if you want each child to have a specific collision/trigger event. If it’s just the root object you need collision events for, you’ll only need the rigidbody on the root (it will use all colliders in its hierarchy).