Game runs great but slowly decreases fps, can't find source of bug

This bug has brought my game to a halt and I’d really like some insight on this. The game runs very well (300fps when uncapped) from the start. About 5-10 minutes in, it starts to slowly decline, declining faster and faster until it’s unplayable.

It doesn’t seem to be the number of actors on the scene, in fact, I’ve tested this by adding way more (double/triple) actors (with AI and movement) and there’s no issue. I’m not adding more components to the scene either, just spawning some actors as the game progresses (which are deleted when destroyed.) The scene isn’t large and the player is confined to the play area.

The weird thing is that the fps shoots right back up if I don’t move the character. Turning the camera or moving WASD causes the fps shoots back down to the slowly declining value again, very quickly. I’m not using any tick events, just carefully created timers, which aren’t relevant to the movement of the player/camera though.

I can provide another stat screenshot or something, I really want to figure this out. Thank you!

Here’s a screenshot of the ‘stat gpu’ and ‘stat unit’

341037-junebugerror.png

I can’t find any info on visibility commands either.

You could try “stat streaming” for more info. I found a bug in my game when I use the Download Image node multiple times and it caused my Texture Streaming to go on an endless loop slowing the game down over time.

Thank you, just tried that and saw something unrelated to fix, so that does help. Still having trouble with Draw and GPU climbing slowly over time when the player character is moving. Any other ideas?

Hi, can you show an image of stat initviews ?

Also are you running your game in standalone? If not, then try to run it in standalone and then do stat initviews

Cause if you’re not running the game in a separate process (e. g. standalone, packaged) then you will also profile the performance the editor uses (and the more windows you have open there the more it will use) which will in the end give you wrong results.

Also GPU time will always be around the frame time, whether you’re GPU bound or not, so in your case you’re most likely not GPU bound but by the Draw thread.

Thanks for the reply, I am playing in the standalone and you’re right, I do think it’s the Draw thread. It seems to be fine as long as I don’t move the camera/player, is that odd?

Here’s the stat initviews screen. Any help is appreciated!

edit: the view visibility is growing as the game goes on, could this be related to visibility commands?

This looks fine

You could take a look at this here GPU Stat Profiling - High MS for VisibilityCommands

and this here Visibility and Occlusion Culling | Unreal Engine Documentation

edit: the view visibility is growing
as the game goes on, could this be
related to visibility commands?

From the docs:

View Visibility The amount of frame
time spent to process Actor visibility
queries.

And AFAIK Visibility Commands is the GPU hardware occlusion culling which is the last step to determine which things should be drawn, so maybe they put the time for that into View Visibility as well but I’m just speculating here. I never had a bottleneck in the draw thread so I don’t have too much knowledge about that.


What you could try is duplicate your level and then step by step remove things (replace player pawn / controller with default ones, remove actors,…) until that problem goes away. So to pin it down the hard way.

Thanks for the answer. In doing what you recommended, taking the duplicated level apart piece by piece, I’ve found where the issue is and that I can cause this bug to happen much faster.

It appears that my projectiles (who become deleted in the world outliner) cause the draw count to rise. The fps and draw stat gets worse when the player moves. I’m not sure what could be going on since the bullets are being deleted (life span) but still cause a permanent fps drop.

Try making a new level and only placing the player controller/character blueprint in it to be sure.
Then if it still happens, look at Tick, and any Loops for repeating events.

Interesting. I had this problem before when I was making an endless arcade styled game. I made the objects delete and spawn over and over which caused that issue. My solution was to not delete and instead to keep only a certain amount spawned, then call them when they are needed.

Probably not the best way to handle that in your case.

Im going to check that out, I might need to do some bullet pooling like you said or figure out if there are issues with the bullets im spawning. thanks!

I’m going to try this and post my results. It’s weird to think that a single bullet can add permanent lag, never would have thought. Thanks!

Then you could take the projectile / projectile spawning logic apart and see whether you spawn anything in there that might not get destroyed with the projectile (e. g. some infinite looping particle system) or again duplicate the projectile class and start removing stuff.

I solved it! It was coming from a way that the bullets were being spawned, muzzle flash specifically. I was adding a Niagara component instead of spawning a one-shot system each time a bullet was fired. Thanks for the help yall, your suggestions helped me find where this was happening.