What is going on with my build?

I’m new to Unity and trying to make a game. The world is quite large, but not too when compared to other games that runs just fine. I only have vegetation around the paths that the player can go and occlusion culling.

The problem is that when I use the profiler, the EditorLoop takes up A LOT of CPU and GPU to the point that the game goes from 60 fps to 12. I don’t know why, before I closed the editor to test on another game that only has a plane, a player capsule and a cube, the main usage was from “application.idle”, and now in both the test and the game it is “application.tick”.

The test still runs at 60 fps in the test but the CPU still has spikes where the ms goes 16x up from previous and it seems in both testings it’s when I control the player and look around. I don’t know what to do since when I built and ran the game it had the same crazy lag.

I don’t know what to do with this or how to fix it. I also wan to point out that even in the testing game with fewer assets my laptop still went crazy with the fan.

First, profile a build to assess the actual performance. I’m sure it’ll be fine.

The editor does a whole lot of other things whether you are in playmode or not. In your case this seems simple and straightforward: 94% of the time goes into rendering the ProfilerWindow because you are currently using it. It’s normal for profiling to slow down the runtime.

What you need to do is look at the things besides ProfilerWindow that take up a significant portion of time and then check if there’s anything you can do about it.

For instance, if you have an Inspector with thousands of items in a list or array, then rendering that Inspector will take quite a lot of time. You would only notice a slowdown when that particular object is selected however and the Inspector window is visible.

Since you’re on a Laptop you may want to close all windows that you aren’t currently using to minimize the time spent rendering the UI.

Thank you for answering.

I did close other windows, but it does nothing. I also ran the profiler with the build and found that it’s Vsync for some reason that takes up the most. I don’t really know what you mean by the Inspector having potentially thousands of items.

I looked at another screenshot I took this morning and it does say InspectorWindow.Paint and it takes 34.1% then sceneview and profiler etc.

I probably should mention that I’m using a Lenovo Legion Y520 from 2017 or something with Intel(R) Core™ i5-7300HQ CPU @ 2.50GHz, Nvidia GeForce GTX 1050 and upgraded 32 GB RAM.

Here’s the screenshot from the build profiler.

Also, I don’t know anything about this, but it’s a little worrying that the cpu and gpu goes over the target by several 100%.

Imagine a MonoBehaviour with this:

public List<string> sooooManyStrings;

And then you fill in hundreds or thousands of items to such a list. While the Inspector of that object is visible, it will eat up quite some time and probably generate garbage a lot too.

Try disabling Vsync in the game view during profiling (it’s a setting in the toolbar).

Try selecting different game objects (create an empty one too) to see how this affects the time spent drawing Inspector. You can also close the Inspector window altogether.

I disabled the Vsync while running the build and it did nothing. I disabled it in the game view before trying the game view and it dropped down below 10 fps while not even moving.

The Inspector thing I just remember was on the test map that I made with only a plane, a cube, a capsule and very short controller script. However, the profiler did kind of change when I selected the different objects to the point where an Application.Idle appeard and took 45%, this was in edit mode profiler.

As the highlights module at the very top of the charts is telling you: the GPU spend 45ms that frame. You’re not VSync bound, you’re GPU bound.

Most of the games you’re probably thinking of here have huge and/or very experienced teams behind them that now how to optimize and fine tune these large worlds in very deep detail. It’s not something that usually just works no matter what content you throw at it.

That said, it’s not necessarily unachievable. Check out these resources:

1 Like

I don’t know what the gpu thing means, but I’ll look it up.

I was thinking more like the newest slenderman game. I’ve only watched a playthrough but it seems big and there are a lot of assets.

I’ll check the links out. Thank you.

What a frame is “bound” by defines what needs to be optimsed to make it faster. I’d it is CPU bound, you need to reduce the time spend on the CPU for the frame to be done faster, if it’s the GPU bound, you need to optimize the GPU. The CPU can also be main thread or render thread bound, depending on which of these is waiting on the other. If it is vSync bound (if vyscn is actually enabled and not just “masking” GPU “boundness”, you have to improve GPU performance by possibly up to of 1/screenRefreshRateInHertz s before you’ll notice a difference because that’s the max frequency at which frames can be pumped out.

Also games like Slenderman make usage of several optimization techniques, like batching, low poly models and low view distances (close far clipping planes) hidden by high amounts of fog/darkness, meaning the vastness of the terrain doesn’t actually need to be processed by the GPU and often gets culled on the CPU already.

So I need to find what it is that is taking up the gpu. I did a profiler test for gpu and it say 99.1% RenderGraph - draw main light shadow etc down to QuadTreeNode.Render. and also DrawOpaqueObjects.

So it’s a rendering issue and that’s where I need to optimize?

I did Occlusion Culling before building and set the camera distance far away that you won’t see a box of nothing in the middle of the screen(except in one place where it’s more of a straight path. I wanted to use fog because of it but it’s still visible through it), but close enough to where it won’t render the things it doesn’t need to.

I did some testing and found out that it is definitely a rendering issue. I removed all the trees and made a build, which doesn’t matter anyway because I didn’t care for the tree placement, I just wanted a barrier so the player couldn’t go wandering in the forest and had to stick to the path, I should’ve probably just used an invisible wall. Anyway, when I profiled the build I still had the spikes and the dxgi.waitforswapchain at 68.7% but the spikes are at 200 fps which I’m going to guess is fine and also no exceeding target frame in either of the cpu or gpu.

I just try doping better tree placement and better fog and invisible walls. The thing about following the path is that at a certain point I want to change the entire map to a darker, night version, but maybe it can be done with some kind of circle area thing instead of a certain point on the map?

Also how do you quote a specific line from a user to answer? I don’t get it.

You select it and there should be a tooltip button to quote.

Anyways, you might also want to look into the shadow casting settings on the trees and your light source, as well as the distance it can light up.

Is it this one? I’m guessing it’s this one. I can see it on the side to the left.

I did check the shadow and the light source this morning acually, after I had posted. It did take me a while to find out where it was, but it kind of worked. Not completely worked, but I managed to randomize around 40.000 trees over the map without the shadows and “dark” lighting, which made it look like evening. At 50.000 I started getting the high gpu usage. I’ll play around with it some more, thanks for your help.

edit: I meant it’s to the right, I swear I don’t know left from right properly anymore.

1 Like