The question is answered, right answer was accepted
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!
Answer by Gloubi · Feb 02, 2020 at 05:09 PM
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 https://github.com/mirrorfishmedia/ProceduralContentGenerationBasics/blob/master/Assets/Scripts/ProceduralBasics/MeshCombiningAreaSpawner.cs
Now everything runs smoothly :) I hope this can help someone else in the future ;)
Follow this Question
Related Questions
How to Limit FPS? vSync problem (WaitForTargetFPS),How to Limit FPS but without VSYNC? 0 Answers
Mobile Performance Issues 0 Answers
Horrible Lag spike when Looking at an object that's showing GUI 1 Answer
GameView.GetMainGameViewTargetSize() problem 0 Answers
Massive Rendering spike in profiler when unloading the scene 0 Answers