Unlit Mode in packaged game

This was supposed to work, I guess. The console command r.ForceDebugViewModes is registered in the engine: https://github.com/EpicGames/UnrealEngine/blob/40eea367040d50aadd9f030ed5909fc890c159c2/Engine/Source/Runtime/RenderCore/Private/ShaderCore.cpp#L366

But it doesn’t work, because it’s not actually used by the viewmode console command processing function:

https://github.com/EpicGames/UnrealEngine/blob/40eea367040d50aadd9f030ed5909fc890c159c2/Engine/Source/Runtime/Engine/Private/GameViewportClient.cpp#L3585

Instead, what we have is:

#if UE_BUILD_TEST || UE_BUILD_SHIPPING
	Ar.Logf(TEXT("Debug viewmodes not allowed in Test or Shipping builds."));
	ViewModeIndex = VMI_Lit;
#else

So it just forcefully sets the view mode to lit in shipping build no matter what option you choose. So, what do we do? Well, one way is to create our own console command that actually works in all builds. Or just replicate the behavior of this Unreal function and put it in a blueprint library and call it from C++ or blueprints respectively. That’s what I intend to do now.

Here’s the solution that actually works:
In your C++ blueprint function library(create one if you don’t already have one):
Header:

UFUNCTION(BlueprintCallable)
static void SetViewMode(EViewModeIndex ViewMode);

Source file:

void UMyBlueprintFunctionLibrary::SetViewMode(EViewModeIndex ViewMode) {
	ApplyViewMode(ViewMode, false, GEngine->GameViewport->EngineShowFlags);
	GEngine->GameViewport->ViewModeIndex = ViewMode;
}