Editor Simulated Platform
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.
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.
UFUNCTION(BlueprintCallable, Category="Common UI", CallInEditor)
static void SetSimulatedUiPlatform(FName PlatformIniName);
void UFtsMenuFunctionLibrary::SetSimulatedUiPlatform(FName PlatformIniName)
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.
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:
UFUNCTION(BlueprintCallable, BlueprintPure, Category="Common UI")
static FString GetRealOrSimulatedPlatformName();
const FName SimulatedPlatformName = UPlatformSettingsManager::GetEditorSimulatedPlatform();
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.