- Home /
hidden children / instantiating as child
I have an empty game object and I need other game objects to appear on the scene where it is and become it's children (it moves and I need them to move too). I was wondering how BAD is having hidden (not active) children inside this empty GO and activate them on need. Is it a big waste of memory/something else/generally bad move?
Would it be better to somehow instantiate those prefabs as empty object's children and then destroy them? I'd love to know that, because soon I'll take care of my armor system which will have similar problem - to hide all armor pieces on character and activate the ones that are equipped or to instantiate them inside the character GO and destroy.
not quite what you're looking for, but maybe this helps: http://answers.unity3d.com/questions/7877/how-do-you-use-a-pool-of-objects-rather-than-creat.html
maybe you can describe exactly what you are trying to do?
Greetz, $$anonymous$$y.
right now I have a square in front of my player which is used to place objects (buildings) on the map on mouseclick.
I want it to show how the building will look - so a transparent version of the actual GO which is going to be implemented. Since I have many different models that can be placed and ability to choose between them, I need to find a way to change those 'holograms' and I thought of two - either have them already as children inside the square GO or to instantiate them when they are chosen and then destroy them. The choice may be done very often so I guess constant instantiation and destruction is a bad move.
with my (limited) experience, I'd agree. have them activate/deactivate is much better than instantiating each time. Don't know any answer to your fundamental question though. I'm curious about that too, but your headline isn't inclined to invite in the kind of guys that would know the answer... =/ Also: what's with the armor-tag? Greetz, $$anonymous$$y.
Answer by Evil-Dog · Jul 19, 2011 at 08:01 PM
Well there are a couple things to consider here
1) Garbage collection is gonna dislike you if you instantiate a LOT of things, now if you're talking armors and stuff that doesn't change often that may be totally fine
2) Memory Usage, if you're talking about a character customization kinda thing, then I assume you'll have lots of armor pieces and having them instantiated all the time may be bad.
By default I would go with Instantiating the armor piece when you need them and then you set the transform's parent of the newly instantiated piece to the "armor container" game object so they become children and move with the container.
However, I don't think inactive objects have a big overhead so if you have only a few armor pieces to handle you could do like you said and activate/deactivate them as necessary.
is there a way to check the memory usage? those hidden prefabs in my example are buildings each made out of other prefabs (wooden logs) inside unity
Your answer
Follow this Question
Related Questions
Instantiate a copy without its children 0 Answers
Instantiate a Prefab as a Child? 5 Answers
Instantiate as child, of child, of child... 3 Answers
Create Clones as children in loops? 1 Answer