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.
Well there are a couple things to consider here
-
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
-
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.