- Home /
Do hidden (inactive?) objects take up processing time.
I am currently playing around with a 3 dimensional array of objects as part of a Unity noob learning project.
I have a 3d array of objects, each of which is made up of 22 other objects. The number of tris per array object is relatively low.
I have a choice:-
A) build the array objects from a prefab (that includes the 22 child objects and then hide the child objects that are not required).
This is the simplest (I create a single prefab with all child objects present I can just instantiate that object for each cell of the array, hide child objects and then unhide them later when required).
B) build the array objects one at a time, adding child objects as required. During play add or remove child objects using the same method.
This leaves the number of objects and tris lowest at start but is far more complicated to do and also makes adding new child objects more complicated (although once the function to add/change an array child objects is written, it can be used for any changes.
The frame-rates for my tests so far with 1000 objects * 22 child objects are surprisingly high with all turned on (*gotta love Unity) but there isn't a huge amount else going on in the scene yet.
Q. If I have 1000 objects (* 22 child objects) but 75% of the child objects are hidden will the hidden objects still be taking up processing time?
Just BTW here's some idiot explaining at length about pools, for new readers
http://answers.unity3d.com/questions/321762/how-to-assign-variable-to-a-prefabs-child.html
Thanks for the pointer - makes interesting reading (I shall read it again several times).
I was concerned about the 'idiot' reference - I should have guessed who the author was though :)
Answer by Owen-Reynolds · May 23, 2013 at 01:56 PM
I've found the overriding concern, as you mention, is complexity. Weird spawn-on-demand tricks seem to always have these infrequent, hard-to-track-down special case glitches. Especially as you make changes and have to track down everywhere/time things get spawned.
Spawn-at-once allows you, early in design, to Pause, manually Activate everything and check your work.
IMHO, inactive game objects don't take any precessing time. They go into a big inactive list which is never looked at during updates (unless you make something active.) That's (my guess) why GameObject.Find
won't find inactives. They will take up memory space, but will quickly be moved to the lowest priority memory.
Thanks for the prompt response - building the whole array and making child objects inactive until required is certainly simpler.
I tested further and ended up with an array of 1000 objects * 22 children. It takes quite a while to create the objects initially and Unity doesn't like me moving the whole lot in the scene editor (not surprising considering the recalculations it has to perform during translation). Fortunately the array itself is location-static and I can now turn on or off any one of the 22k objects as required.
I have converted this to a comment for you.
Edit : no worries =]
Hi, thanks for the pointer, I did try and convert to comment after I posted (when I realised my mistake) but you are just too quick off the mark for me (today) :).
Your answer
