Editor Simulated Platform

06 Jan 2024

Unreal (5.3 as of writing) has a way to simulate target platforms in editor. I knew about the Mobile Rendering Preview, but while reading through engine code I found out there is a way to make Common UI think it’s rendering for a different platform.

Simply pass in any FName for a platform to a static method of UPlatformSettingsManager

static void UPlatformSettingsManager::SetEditorSimulatedPlatform(FName PlatformIniName)

Common UI queries which platform it is running on to determine which icons or traits to use. If the simulated platform value is anything else than None it will get that platform instead of the actual one the editor is running on.

Using it in Blueprints

I have not found a blueprint exposed way to use it, but it’s easy enough to write a small wrapper method in a function library. Be mindful though that the simulated platform only exists with editor context so there’s an #ifdef guard in the implementation.

.h
UFUNCTION(BlueprintCallable, Category="Common UI", CallInEditor)	
static void SetSimulatedUiPlatform(FName PlatformIniName);

.cpp
void UFtsMenuFunctionLibrary::SetSimulatedUiPlatform(FName PlatformIniName)
{
	#if WITH_EDITOR
	UPlatformSettingsManager::SetEditorSimulatedPlatform(PlatformIniName);
	#endif
}

With that I created a small Editor Utility Widget that has a String Combo Box with the different platforms and whenever one is chosen the platform is set.

A blueprint connecting the result of a combo box to the set platform call and an example of a few platform names

Going Further

In my project there’s more multi platform code and it essentially centers around UGameplayStatics::GetPlatformName calls. This means even when setting the simulated platform only Common UI code reacts to it. To fix this I added a new method that mirrors what Common UI does internally:

.h
UFUNCTION(BlueprintCallable, BlueprintPure, Category="Common UI")	
static FString GetRealOrSimulatedPlatformName();

.cpp
FString UFtsMenuFunctionLibrary::GetRealOrSimulatedPlatformName()
{
	#if WITH_EDITOR
	const FName SimulatedPlatformName = UPlatformSettingsManager::GetEditorSimulatedPlatform();
	if(!SimulatedPlatformName.IsNone())
	{
		return SimulatedPlatformName.ToString();
	}
	#endif	
	
	return FPlatformProperties::IniPlatformName();
}

Lyra

After posting this Article to the Ben UI Discord I was told that the Lyra Sample Game uses this functionality too and did a quick check. Lyra has an entire class called ULyraPlatformEmulationSettings that does this and a few more things so I’d recommend to check it out.