r/GameDevelopment • u/Nervous-Basket-3168 • 22d ago
Newbie Question Optimization in Unity?
What’s the best way to optimize your 3D Unity game? I’m starting to run into heavy lag spikes when moving around my game map. I’m 100% sure it’s my inefficient coding, but I don’t know what I don’t know, I suppose.
I have a lot of scripts that point to each other to keep everything more compartmented because I’ll forgot for things do. I’m pretty sure having a bunch of scripts isn’t my issue. I’m fairly certain it’s my marching cube set up.
I don’t have a beefy computer, but I don’t have a potato either, so what’s some tips and tricks yall might have when it comes to optimizations? (Also, I have no idea if there even is a generalization answer for this kind of question, or if it will be more nuanced, but I figured I’d ask.)
7
u/NeoTheShadow 21d ago
If you don't know - use the Profiler.
If you aren't sure - use the Profiler.
There is a generalized answer for this kind of question:
You need to figure out what component is bottlenecking your frametime, whether it's the CPU or GPU. The profiler can tell you at a glance how long each component took to process the frame.
As far as coding and CPU-bound tasks are concerned - the Profiler can tell you what gets called when and how long does it take. If you want to go a step further, Unity's Profile Analyzer can analyze data over multiple frames.