Performance issues with many objects/lights

Hello!

I’m currently struggling a bit with performance. I do not really understand how to use the profiler properly to see what’s going on.


My game consists mainly of:

  • a tunnel, that I generate randomly at runtime around a Bezier curve (I compute all the vertices, triangles, and uvs and create the mesh from that)
  • cubes, with a light component and an emission texture, “spawned” from a pool of 300 objects
  • a few other but rare objects, so probably quite insignificant

Here you can see the profiler with the cursor placed on a “normal” time, when FPS is quite high


And here you can see the profiler with the cursor placed on a “performance spike” time, when FPS gets lower.


In general, on my computer, both normal and spike time are very playable as you can see (around 100 FPS at worst), but on my Android phone, this gets terribly laggy and barely playable (even a very recent phone like the OnePlus 7T is still much less powerful than a desktop computer!)


What I have tried so far to improve performance:

  • disabling the lights on the cubes
  • disabling the emission texture of the cubes
  • marking my custom tunnel mesh as static (but I believe this has no effect on an object created at runtime?)

No significant improvement observed.


My questions are:

  • how to determine what slows the game down?
  • how to determine what causes those spikes?
  • how can I improve the performance overall?

Thank you!


Found the answer to my questions: what was slowing down the whole thing was that, since I had a lot of cubes as single meshes, Unity had to draw each of them individually, which is very costly. The solution is then to combine the meshes together. I copied and modified this script ProceduralContentGenerationBasics/Assets/Scripts/ProceduralBasics/MeshCombiningAreaSpawner.cs at master · mirrorfishmedia/ProceduralContentGenerationBasics · GitHub

Now everything runs smoothly :slight_smile:
I hope this can help someone else in the future :wink: