Mathieu Morenas

Lead Artist / Environment artist

By

Optimize an Unreal Engine 4 scene

presopti-01

After a recent talk about optimization with a tech artist, I realised that I’ve never detail my habits about this important subject. I’m not gonna share all the LOD’s and modelisation stuff with you, but something a bit more complicated, to optimize your final scene.

I’m gonna take Spaceship hangar as a concrete exemple. So Spaceship hangar is powered by unreal engine 4 wich provide us lots of crazy tools to optimize a scene.

PresHangar-01

First thigs first. To test the efficiency of a scene, you’ll have to test your scene on your targeted hardware. For me it was quite obvious, my own PC. A good old Intel dual core E8600 with 4Go of RAM and a GTX 760. Of course the goal is to get, at least, 60 FPS.

If you wanna get the most realistic result, kill every useless aplication on your computer, and trun off the realtime option in unreal editor. Go to project settingsGeneral settings,  serch for smooth frame rate and turn it off. Then launch your scene as a standalone game, and minimise unreal editor. Once it’s loaded, you can swich to full screen by pressing atl + enter.

Now we’re good. It’s time to see what’s appening. So press the ” 2 square button “ on your keyboard to show up the command line, and tap « stat fps ». Now you got the real time FPS, but it’s not enought. Then tap « Stat Unit ». We finaly have all we need to see what is going on.

    • « frame » is the overall frame time to draw it
    • « game » is your game thread, the time that gameplay/gamelogic takes
    • « draw » is the rendering thread
    • « GPU » is GPU times to calculate a frame that’s why frame and GPU are similar

You can have the real time graph of those four data by taping « stat UnitGraph ».

stats

16ms per frame is around 60 fps. If you see any problems, or frame rate falls, it’s time to go further.

In my case, I’ve optimised every model with LOD, etc. and tried to keep shaders as simple as possible. But it’s a cinematic. So the goal is to get the most beatifull scene. When I create my lighting and post process, I dont realy take care of optimization. Of course if it’s laggy in the editor I make some adjustments. But I just try to get something nice and with the best atmosphere. That’s why on my first load, my fps was around 40 – 45.

shadercomplexThe first thing I tried, is pressing F5 (F3 to back to normal) to check my shader complexity. If you have particles, or lots of transparency, you might have frame rate issues because of the shader complexity. This view can also aware you about involontary duplicate / overlaping objects.

The next things to do is to dig deeper into render data.profilegpu

So tap « profile GPU ». GPU Visualizer will take a « screenshot », and show you at this exact moment, how much time, each and every little things on your scene, takes to your GPU to calculate it. For me, of course, lights was the bottleneck. I checked every lights, and figured that too many of them was casting shadows or in a too wide radius. It was time to trade-off to keep my atmosphere without all those lights / shadows. By doing this and other little adjustments, I rise my FPS up to 70.

sessionfrontendIf you have any problems with your game or draw stats, in other words with your CPU, there is another tool. Tap « stat startfile » and play to your game to capture the data you’ll analyse later. When you consider, tap « stat stopfile ».

Go back to the unreal editor, and open « session frontend » in Window → Developer Tools. Click on the profiler tab, and load the file you just record. Dont worry, the popup will open at the roots of all your captured file, just open the good one. When it’s loaded, you can choose a precise moment or drag to get an average of what appened durring this laps of time. For exemple under « renderThread » I’ve oppened untill I reached my lighting render data, and it was 50.8% of my render time. With this tool you can also check every steps of your blueprint to know what takes time !!

You’ll find more tools and futher information in the unreal documentation. https://docs.unrealengine.com/latest/INT/Engine/Performance/StatCommands/ Have fun !

See ya.