Issues with GameObject Instantiation and Performance

Hello everyone,

I’m currently working on a project in Unity, and I’ve run into a problem with instantiating GameObjects that is affecting my game’s performance.

Issue: Whenever I instantiate a large number of GameObjects at once, my game experiences significant lag and frame drops. I’m trying to find a more efficient way to handle this, but I’m not sure where to start.

Details:

  • I’m using Instantiate() to create multiple enemies at once.
  • The instantiation occurs within a coroutine to manage the timing, but the performance still suffers.
  • I’ve tried pooling objects, but I still notice performance issues when I spawn them in bulk.

Questions:

  1. What are the best practices for instantiating multiple GameObjects without causing lag?
  2. How can I effectively implement object pooling to improve performance?
  3. Are there any specific settings or optimizations in Unity that I should consider?

Any advice or insights would be greatly appreciated!

Thank you in advance for your help!

this is normal, instantiating is not that quick, so depending on what you call large, yes, it can take time… If you’re pooling the general gist is that you spawn enough in advance and the pool disables them and only enables not makes them on demand… (to an extent) so say a bullet pool, you might decide 400 bullets is your max, well you also might know that it will be perfectly normal to have 100 on screen so, you premake the 100, with allowing to grow to 400…

or you learn entities :smiley:

1 Like

Use the profiler to find out what causes the spike. You’ll be able to see if its physics related or if its caused by a script. Or perhaps the demand is on the rendering engine?.

1 Like

2022.3+ has Object.InstantiateAsync: Unity - Scripting API: Object.InstantiateAsync