- Home /
Pooling or Instantiating Enemies?
Making a game for mobile.. What would be better on performance? Pooling or Instantiating Enemies?
Answer by ThePunisher · Dec 07, 2013 at 12:33 AM
Oh man, that's a simple answer. Pooling is much more efficient than having to destroy and instantiate/initialize several objects repeatedly, each containing several components.
We had a game loading a scene which was blowing away a bunch of plants from the previous scene and instantiating new ones. This scene would take several seconds to load up and then would still cause a lag spike as the objects were initialized. Once I changed it to pool the plant objects and simply update the textures and animations it completely removed the lag spike.
Ok so that answers that! Thanks. Ive started to pool the enemies but ran into the issue of my enemies(Jets) no longer find the player using FindTag & LootAt. $$anonymous$$y Jets just sit there... Ive made a Script to find the all the transform by name and then force the ones that i find by specific name and force them in a transform Array and add individual numbers on the end of the names so i can look them up by way of "Jet_0", "Jet_1", "Jet_2"...etc..
Just cant figure out why my jets cant find my player
Well, if you are pooling your jets now they are definitely not calling Awake and Start, and that's probably where you had your logic for finding the player. You'll have to call some initialize method on them as soon as you re-use them out of the pool.
Answer by Raiden-Freeman · Dec 07, 2013 at 12:41 AM
If the amount of enemies is low, it doesn't matter. It also depends on their meshes/textures and other things, like the phones you're targeting.
The amount of enemies are low but i have already pooled around 800 to 900 building gameobjects above the camera to be used for city destruction so i could just switch different types of the same building out.