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)?
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.
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.