- Home /
Instantiating Objects
Hello,
I've been told in the past that spawning large numbers of objects at a time is kind of a bad practice. That said, I'm making a tower defense game so, I'm going to need a lot of enemies spawning at once. What would be the best way to do that? Spawn them one at a time when I want them to go, spawn all the ones that are going to be needed in a round at the very beginning, or was I informed incorrectly and instantiating a bunch of objects isn't all that terrible? Maybe some other option I didn't list. I'm not too knowledgeable about the inner workings of Unity, so any input on the matter would be lovely. It'd be nice to know what my best option for deleting them when they die would be too.
Thanks!
Answer by yathishgk · Jul 08, 2016 at 07:22 AM
Use the concept called Object Pooling. Instantiate the specific number of objects initially and reuse them . Don't destroy the instantiated object every time which increases to GC calls. So keep the instantiated object at the pool and use them by may be enabling n disabling and changing their positions.
Your answer
Follow this Question
Related Questions
Removing instantiated objects?? 1 Answer
Show/hide object in C# 2 Answers
How do I destroy a Instantiated UI image that is pushed on the Canvas? 2 Answers
Destorying prefab and instanstiating again? 0 Answers
instantiate object 2 Answers