Optimization: instantiating vs built in scene

I am learning more about optimization, and am building a tower defense game. I am working at reducing draw calls, but have a few fps spikes when instantiating a new turret on to it’s spawn point.

I read it can be a drain when instantiating new objects, but would it be better to have each spawn-point have all versions of turrets inactive, then activate the desired turret rather than instantiate it on command?

The turrets are somewhat detailed, and given how many spawn points there are in a scene, I worry this would be like adding 100X more objects into the scene than would be created from instantiating. I have not tried it yet because it would require rewriting 80% of the game mechanics so far.

Thanks in advance!

Hi!

I haven’t understand well how optimize draw calls and instanting are linked but, as I understand, I think you have two different problems to solve:

  • Draw calls: to reduce the draw calls, you should a technique called “Texture Atlasing”. Google that for more infos (there are also a lot of good plugin on the asset store to do that!). Long story short: you make a single texture out of the various texture you have (less texture = less materials = less drawcalls!)
  • Instantiating: Instantiate and Destroy are a sure way to have a lot of spikes on your fps! To avoid that you should another technique called “Object Pooling”. You can do that in a lot of ways! Here a tutorial by unity! Shortly: you instantiate (before the beginning of your level) all the tower you could need in a position far far away from camera (or simply turned off), that’s you “pool”. When you need a tower, you don’t instantiate that but you pick the right one from the pool and you put that in the right place!

There’s a lot to say on both topics… I hope I have understand correctly what you need and gave you a good hint! :slight_smile:

1 Like

Ahh Thanks!! I think the pooling solution is what I am needing, in addition to more atlasing. I unfortunately, made most of my assets before I understood what texture atlasing was, so I am going back now to combine more UV’s and get as many objects on to single textures as possible. The Pooling technique is new to me, but that explains a lot. I would only have that FPS spike the first time I brought in a turret of that type, so this could fix the issue without having to overload my scene. Thanks again for the advice! :slight_smile:

1 Like

For the atlasing you can use some plugins that can do that without using a third program and editing the UVs! :slight_smile:
In the past I used Mesh Baker. Obviously now that you know that you can make your assets with this in mind! :wink: