- Home /
Possible way to improve performance moving large hierarchies?
In our project we have objects that consist of many child objects (i.e. object with ~2000-3000 childs). The childs are pure transforms with meshrenderers.
We noticed the following: Moving and rotating the root-object will consume more cpu time the more child objects are parented to the root-object.
In example to move and rotate such a hierarchy transform.position and transform.rotation has to be called, which both consume about the same time.
Are there any possible ways to get around this or speed up the process?
Answer by brunocoimbra · May 17, 2016 at 07:53 PM
The short answer is: no.
The long one:
When moving the root object, Unity needs to move all theirs childs to the relative position (the same goes to rotating and scaling). So, no, there is no way to "speed up the process", at least not one that doesn't relly on a new CPU or overclocking the one you already have (and even doing anything like that, the difference would not be that much).
One thing that I would reccomend is to not parent that large amount of objects to the same root one when you know that you will need to move the root one.
Also, the only reason I see to parent ~2000 objects with meshrenders to a commom root one would be to organize the scene, but a good practice is to keep the root one at the (0,0,0) JUST for the sake of keeping the hierarchy organized, not for moving that amount of objects at the same time.
Thanks for your response. I get your point. Although it is necessary for our project to have that amount of renderers on a moving object. The reason for this is, that we have very complex moving 3d-$$anonymous$$odels consisting of >20 million triangles. We are already combining meshes to reduce the amount of transforms needed.
What if we would do the rendering "ourselves" by setting up the transform matrices with Unity-GL interface (i.e. GL.$$anonymous$$ult$$anonymous$$atrix (transform.localToWorld$$anonymous$$atrix)? Or would that create way too much overhead.
I am not sure, as I didn't ever touched the Unity-GL interface, but I guess that it would not change much.
Why do I guess that?
Pick that root object that contain ~3000 childs and put it's position, direct in the inspector, as 10. The overhead is still there, right? Put again it's position as 0. Same, right? I told you to try that because, that way, Unity would only need to recalculate those position once, as re-rendering once too (when dragging the transform, each mouse movement requires a new calculation, being "heavier" to do transform's modifications that way).
So, as you can see, even when only updating the render once, the overhead is still there.
$$anonymous$$eep combining meshes where you can and create smaller hiearchies to move not combined meshes together. You can still have a root gameobject to keep all your level stuff, but separate it's childs into "sub-root" objects (the ones you will change the position, rotation and scale) to not make those transforms modifications that heavy.
Your answer
Follow this Question
Related Questions
Issues with copying Y axisrotation of another object 2 Answers
Calling gameobject.transform vs. just calling transform directly - Performance negligible? 1 Answer
Coroutine - transform for every frame for duration? 0 Answers
How Do I Give Two Objects the Same Transform? 1 Answer
Changes of Transform cancel on next frame after change 1 Answer