Why does disabling an object eliminate its transform performance cost?
I have a parent object with a child object that has several hundred box colliders attached (why I have to do it this way is a long and frustrating story). When I move the object, my game naturally falls to about 2 FPS. When I disable the child object, the object moves as if nothing were ever attached to it. When I stop moving it and reactivate the child object, all have the colliders have followed along.
Why is updating the transforms of disabled objects so cheap performance-wise?
hello, moving a gameobject is a really fast task, so the performance issues comes from the physics part for sure, maybe all those colliders are colliding with each other? can you make sure in the project settings - physics - layer collision mask, they are not colliding if they are in the same mask?
I looked at the profiler, and 97% of CPU use was co$$anonymous$$g from Physics.SyncColliderTransform. Also all of the colliders are not their own child objects: they are all components attached to a single child object, so I doubt that they are colliding with eachother.
I think the performance drop is co$$anonymous$$g from having to go through and sync the transforms of each of the hundreds of colliders attached. I'm just not sure why the colliders still follow the gameObject without ANY performance cost if the child object is disabled. Doesn't it still need to sync their positions, for if/when the gameObject is reactivated?
Answer by Casiell · Jan 30, 2019 at 07:23 PM
When you move an object Unity has to calculate positions of each and every child each frame you change the position of parent object. When object is disabled Unity doesn't give a damn about those calculations and only moves enabled objects. When you enable your children, Unity calculates the position change only once and moves the children directly to that position
Edit: Note that it's massively simplified, but that's the general idea