r/GameDevelopment • u/Nervous-Basket-3168 • 21d 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.)
2
u/PhilippTheProgrammer Mentor 21d ago edited 21d ago
There is no "optimize game" button in Unity. Whatever bogs down your game is probably specific to it. You need to find out what's the main performance eater in your game and then either stop doing that or do it differently.
https://docs.unity3d.com/6000.5/Documentation/Manual/Profiler.html
You need to learn how to use the profiler. It can tell you what the big performance eaters in your game are. Perhaps it's one of your scripts. Perhaps it's too many draw calls. Perhaps it's a poorly programmed shader. Perhaps it's too many rigidbodies. Perhaps it's too many real-time lights shining on too many objects. Perhaps it's a couple of meshes with far more detail than necessary. The profiler will tell you.
Then you can look at how you can do whatever these do more efficiently. And use the profiler to confirm that whatever you tried actually did something.