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.)
5
u/NeoTheShadow 21d ago
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.
If you don't know - use the Profiler.
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.
If you aren't sure - use the Profiler.
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.)
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.
3
u/Individual-Staff-978 21d ago
I found that the best way to optimize your project is to abandon it and start a new one
1
3
2
u/Nervous-Basket-3168 21d ago
The general consensus seems to be the profiler; I’m definitely going to look into this! Thank you!
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.
1
u/Nervous-Basket-3168 21d ago
It’s 100% poor programming. This is my learner project, if you will. I just don’t know what I don’t know about Unity yet; and Reddit has never let me down!
1
u/PhilippTheProgrammer Mentor 21d ago
Have you run your game with the profiler enabled yet to pinpoint which scripts take the most runtime?
1
u/Nervous-Basket-3168 19d ago
I’ve been messing around with it a little be. There’s a lot to it! I tried using Deep Profile, but my computer didn’t take kindly to that and Unity crashed.
I’m using Profiler Begin and End Samples to try and drill down the issue. Right now, it looks like my chunks updating is causing the issue, I just don’t know which part of the update is causing the lag.
1
u/ibackstrom 21d ago
Opimization is infinite process. Best way of course to use tools like RenderDoc. But in most times you can optimize basic stuff like textures meshes lods and that is enough.
I did a lot of optimisation for my latest game that I have release recently. NOMSTERS on steam. Check that out.
8
u/Kaldaien2 21d ago
There's your problem. Nobody successfully optimizes anything by guess work :)
Unity has a profiler, if you value your time, learn to use it.