- Home /
Setting position on parent transform with many children - performance
I was wondering what happened when updating the position of a parent transform with many children. Will all of the childrens positions be updated to their new world space positions or is Transform.position a calculated property?
If you move the parent then all the children should move with it(their position is calculated in relation to the parent(local). There are some exceptions to this, one being that if a child has a rigidbody then it will be moved by the physics engine independently of its parent. Also if you child objects have a different scale to the parent(or sometimes if any of the objects, parent or child, have a scale that is not (1,1,1)) then the movement can also be scaled(smaller or larger depending upon the scale being smaller or larger)
The best thing to do it to try different setups, play with the transform settings (scale etc) and observe what happens as a result. :)
I know the children will have new positions in world space i their parent is translated - but what I would really like to know if this new position is calculated immediately or if the property returns a calculated value based on localposition and the hierachy. The reason is that I was considering moving large areas around including terrain and hundreds/thousands of objects. Basically translating the whole game world.
I don't know the answer to that, could you do a quick timed test in a new scene moving them individually in one test and via the parent in another test to see if you get any difference in performance?
Remember to cache your transforms if you do this, otherwise there is the chance that it could alter the results in favor of doing it via the parent move method ...
Thanks that was a good idea. I was planning to deal with floating point imprecisions in a huge world by dividing it into a number of large squares (like 256*256 units) and always have the square with the character controller be at world zero. When moving the character controller to another square this new square should be translated to world zero (and the same translation applied to every other square). That way all objects close to the camera should have many digits of precision. If every single transform will be translated explicitely then I don't think it's feasible:)
Your answer
