Debug Shipping Builds In Unreal Engine 4.23

Debug Shipping Builds In Unreal Engine 4.23

Recently I've upgraded a personal project to Unreal 4.23 and found that we had a crash in Shipping-only! So I needed to figure out how to debug this.

The error I was getting was:
"Fatal Error Material not found" Line 2046

I tried to reproduce this issue in a Development build, but everything was fine. Looking through the logs sadly didn't reveal anything unusual, where I was wishing to see something warning in Development that may crash Shipping.

So step 1 was to find this error message in the code to try and understand it more, so I grep'ed the engine source:

$ grep -riI "Fatal Error Material Not Found" Engine/Source/Runtime/*
/g/Unreal/UE4.23/Engine/Source/Runtime/Engine/Private/Materials/MaterialShared.cpp:             UE_LOG(LogMaterial, Fatal, TEXT("Fatal Error Material not found"));

Aha! Found the error in MaterialShared.cpp.

Because we're in a Shipping build, attaching and trying to breakpoint at this location does diddly squat. However, looking through the previous lines, I can see Unreal is writing a bunch of potentially useful information to the log. Thing is, Shipping builds don't have logs (by default).

To enable logs in Shipping builds, you need to add some extra settings to your game module's Target.cs file.

public class GameTarget : TargetRules
	public GameTarget(TargetInfo Target) : base(Target)
		Type = TargetType.Game;

		// enable logs and debugging for Shipping builds
		if (Configuration == UnrealTargetConfiguration.Shipping)
			BuildEnvironment = TargetBuildEnvironment.Unique;
			bUseChecksInShipping = true;
			bUseLoggingInShipping = true;

		ExtraModuleNames.AddRange( new string[] { "Game" } );

This snippet courtesy of Gossy on the Unreal forums:

Because these settings are changing how the game and engine binaries are being built, this requires us to build our project using the full Unreal Engine source. So download the Unreal Engine source and get that setup (see Epic Game's GitHub for the full instructions on how to do this).

Make a few cups of coffee and probably a good meal for yourself as you fetch the engine, run the setup.bat, rebuild your project for the full engine source, then build your shipping build from the engine source...

Once you have your new build, run the exe with the "-log" flag set and you will get a second window appearing with your log!

Here I now can see the failing material that is causing my Shipping crash. I can return back to the published Engine from the Epic Games Launcher and try to fix it.