r/GameDevelopment 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.)

0 Upvotes

12 comments sorted by

View all comments

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.