- Home /
gameObject.SetActive (false); stored in memory?
Hey guys, I am just curious to know whether or not my game objects are stored in memory when I use this. Probably a simple answer but it's been bugging me for a while and I believe it replaced setActiveRecursively which is what I used to use. Any help appreciated :)
When I say stored in memory, what I mean is... will it cause lag spikes if it is set to inactive (if I have a lot of models set to inactive)?
Answer by Khada · Mar 11, 2013 at 01:03 PM
Read here for details on the changes to active states, but essentially you're correct about it replacing setActiveRecursively.
The object is not deleted and recreated, they are simply disabled. There should be no lag spikes due to the act of enabling/disabling an object unless the object itself causes such behavior.
Answer by Owen-Reynolds · Mar 11, 2013 at 03:50 PM
The standard trick (inside Unity) is to have a list of Active objects and another one of inactive objects. But then, the program only ever looks at the Active list.
So, if you have 10 actives and 10,000 inactives, sure those 10,000 take up the same memory as when they were active, but the game loop only runs 10 updates, collisions only check 10 things. The rule that GameObject.Find
won't find inactive objects is because it only searches those 10 things. Overall performance is as if the inactives never existed.
They also only sort-of take up memory. The operating system and CPU put infrequently used memory in the low-speed area, or even out to disk. So inactive objects will pretty quickly get moved "out of the way." So, on a PC, you could have many more objects than will fit in memory, as long as the actives one will.
Thanks for the information, I feel I understand it fully now :)
Your answer
Follow this Question
Related Questions
physics.OverlapSphere colliders 1 Answer
Wii graphic specs 1 Answer
Problems with large script 3 Answers
How do I calculate how big my struct is? 2 Answers
bug or new feature ? 1 Answer