- Home /
Do empty transforms take up much CPU power?
So long story short, I'm developing a game for Mobile set in a city and there are a lot of objects being brought in and out of play as the player moves about.
I have tried numerous methods for seamlessly loading in/out objects.
First I tried instantiating and destroying objects for loading/unloading. This had noticeable spikes for even loading in something simple like a generic 3D box.
Second attempt, I put the Instantiating/Destroying calls into their own Coroutines, this made the spikes less severe, but they were still noticeable.
Thirdly, I decided to pre-instantiate all the objects I'd need and then keep all the ones not in play as deactive (SetActive(false)). It turns out that setting active to true (even done inside a coroutine) had worse performance than instantiating the objects.
So, I finally arrived at my last idea for loading. I preloaded all the needed objects, then manually went through each one's children, disabling each component that could use up CPU. Such components as scripts, renderers, colliders, audio sources, particle systems, rigidbody (set to isKinematic = true) etc were all disabled, leaving only an object with children transforms. Now I can finally enable an object (enable all its components) and the game has no spikes in performance.
However, this last solution has its own draw back. If I preload too many objects the games FPS will be significantly impacted. Event though there is nothing enabled inside the object besides its transforms.
So my question is, does having many transforms (non moving) in the scene cause a significant hit to the CPU usage? and, If so, what is the best way to do continuous loading/unloading of game objects for Mobile?
Be sure to mark your objects as static if they aren't going to be moving. I don't know for certain, but it seems that would have a large impact.
Have you checked to make sure that, it is all the components combined, are causing the spike, or if maybe just one or two components, that are causing the spike?
$$anonymous$$aybe a component (script) makes some expensive calls in a OnEnable/Awake/Start method that causes the spike and not all the components together. Just a thought.
supernat: I just meant that objects out of play (set to inactive withing the game system) are not moving around or anything. They are just a transform (with possible transform children) that is sitting in an idle state. When brought into the game, these objects might be moving. Thus I cant set them as static, as that is reserved for objects that are never moved or disabled etc.
Code$$anonymous$$aster$$anonymous$$ike: I went through a series of tests, and yeah it turns out that even if every component in a prefab object (including all its children transforms) is set to disabled (enabled = false), game performance still takes a hit if there are a lot of these objects. Simply calling (SetActive = false) on the remaining transform/gameobjects within the prefab causes the performance to go back to normal. So it appears that having a bunch of empty transforms in a scene will have pretty big performance hits (im talking low 1000's of transforms on mobile though).
Answer by Ericool · Mar 24, 2015 at 05:05 PM
put them all in a static array within a script that is init but not updated , create a method to return the ref w/ param an index . But the simpliest solution is to design your architecture first . Nothing should unused for no good reasons .
Your answer
Follow this Question
Related Questions
How To Keep GameObjects From Enabling Again? 2 Answers
Why does Unity disable the Collider when I Destroy the Rigidbody? (2D) 1 Answer
When to Destroy Multiple Items 0 Answers
[solved]how can i enable or disable a component of instantiated objects? 5 Answers
Why are my cached (in an array) gameobjects disappearing? 0 Answers