Best method to Fade screen to black / white in Unreal Engine

Unreal Engine has a built in screen fading function. This lesser known feature is found on the PlayerCameraManager. The Camera manager is itself a goldmine of useful helper functions. Since the Camera Manager is otherwise never interacted with few developers know it exists or know the power held within.

The Camera Manager offers a StartCameraFade function with which you can easily add a screen fade to black or white to your game. If you select the “Hold when Finished” option then a second later call to EndCameraFade will be required to clear the fade.

Between StartCameraFade and EndCameraFade with little effort you can hide the jerky frame timing between level loads or hide a camera cut.

Fading to white requires setting the “Color” parameter to white.

Note: By default the parameter “To Alpha” is 0. Instead you must make it 1 in order for the fade to appear. The default parameters of “from” and “to” both being 0 means by default StartCameraFade fails to create a visible fade.

Dither based transparency in Unreal Engine’s Material Editor

When optimizing TINY METAL for the Switch a technique I have started using is dithered transparency. To use dithering in Unreal Engine you can use the “DitherTemporalAA” node.

A couple years back Adrian Courreges’ graphics study of GTA V brought to my attention how dither could be useful even for modern games. In TINY METAL we use a dither based transparency for the area of movement and area of attack visuals.

The purpose of using dither instead of vanilla transparency is to eliminate pixel overdraw. You can see the net result in Unreal Engine’s per-pixel shader complexity buffer view below.

Overall this was a small but meaningful optimization. It ensures that our frame time does not jump when players begin moving units and half the screen files with movement ranges.

From experimentation dither based transparency works well for large consistent levels of transparency with animated fade-in and no movement. The fade-in being helpful because it gives TAA time to adjust. The no movement being vital because otherwise TAA smears the dither where it should not generating glitches. Attempting to use it with symbols or UI resulted in ugly 90’s era visual side-effects and I do not recommend using it.

Convert std::string to FString; the quick method

A quick method I use for transforming a C++ standard library string to an Unreal Engine FString is to call c_str(), the base c string export helper, on a std::string. Provided the result is being implicitly convert to an FString this method will work.

std::string a = “hello”;

FString b = a.c_str();

This method is shorter and simpler than the canonical method Epic Games recommends which calls for an explicit cast. An explicit cast is only required in cases where the compiler cannot otherwise deduce that the result should be an FString.

RunUAT and SkipCookingEditorContent

When building an Unreal Engine 4 project from the command line the default behavior of RunUAT is to include all Unreal Editor content as well. This bloats packages but is the safest default behavior. I urge you though to build without editor content. This will ensure your packages are smaller and prevent any assets in your game from depending upon editor content by accident.

To build an Unreal Engine 4 project from the command line using RunUAT pass the “-SkipCookingEditorContent” argument in your call to RunUAT.

Example:

RunUAT.bat -SkipCookingEditorContent BuildCookRun -project=PATHTOPROJECT