If you have followed the previous recipe, you will notice that when you use Play In Editor, the button that loads is unusually small.
The reason for this is UI Scaling, a system that allows you to scale the user interface based on the screen size. User interface elements are represented in terms of pixels, usually in absolute terms (the button should be 10 pixels tall).
The problem with this is that if you use a higher-resolution panel, 10 pixels might be much smaller, because each pixel is smaller in size.
The UI scaling system in Unreal allows you to control a global scale modifier, which will scale all the controls on the screen based on the screen resolution. Given the earlier example, you might wish to adjust the size of the button so that its apparent size is unchanged when viewing your UI on a smaller screen. This recipe shows two different methods for altering the scaling rates.
PlayerController
subclass. Call it ScalingUIPlayerController
.BeginPlay
:virtual void BeginPlay() override;
Super::BeginPlay(); TSharedRef<SVerticalBox> widget = SNew(SVerticalBox) + SVerticalBox::Slot() .HAlign(HAlign_Center) .VAlign(VAlign_Center) [ SNew(SButton) .Content() [ SNew(STextBlock) .Text(FText::FromString(TEXT("Test button"))) ] ]; GEngine->GameViewport->AddViewportWidgetForPlayer(GetLocalPlayer(), widget, 1);
GameMode
subclass called ScalingUIGameMode
, and give it a default constructor:ScalingUIGameMode();
ScalingUIPlayerController
:AScalingUIGameMode::AScalingUIGameMode() :AGameMode() { PlayerControllerClass = ACustomHUDPlayerController::StaticClass(); }
Config
folder:DefaultEngine.ini
inside your text editor of choice.[/Script/Engine.UserInterfaceSettings]
section:[/Script/Engine.UserInterfaceSettings] RenderFocusRule=NavigationOnly DefaultCursor=None TextEditBeamCursor=None CrosshairsCursor=None GrabHandCursor=None GrabHandClosedCursor=None SlashedCircleCursor=None ApplicationScale=1.000000 UIScaleRule=ShortestSide CustomScalingRuleClass=None UIScaleCurve=(EditorCurveData=(PreInfinityExtrap=RCCE_Constant,PostInfinityExtrap=RCCE_Constant,Keys=((Time=480.000000,Value=0.444000),(Time=720.000000,Value=1.000000),(Time=1080.000000,Value=1.000000),(Time=8640.000000,Value=8.000000)),DefaultValue=340282346638528859811704183484516925440.000000),ExternalCurve=None)
UIScaleCurve
in that section.(Time=x,Value=y)
pairs. Edit the second pair so that its Time
value is 720.000000
and the Value
is 1.000000
.r.setreswidthxheight
to change the resolution, and observe the changes that result from doing so.PlayerController
, we need a custom GameMode
to specify which PlayerController
to use.PlayerController
and GameMode
, and place some Slate
code in the BeginPlay
method of PlayerController
so that some UI elements are drawn..ini
file format that has been commonly used with Windows software.[Section Name] Key=Value
UserInterfaceSettings
class, with a property called UIScaleCurve
on it.UPROPERTY
is marked as config, so Unreal serializes the value to the .ini
file.UIScale
data in the DefaultEngine.ini
file, in the Engine.UserInterfaceSettings
section.Time
, Value
pairs alters or adds new key points to the curve..ini
files yourself, and for designers, it is an intuitive way to edit the curve. However, having the data stored textually allows for programmers to potentially develop build tools that modify properties such as UIScale
without having to recompile their game.Time
refers to the input value. In this case, the input value is the narrower dimension of the screen (usually, the height).Value
is the universal scaling factor applied to the UI when the screen's narrow dimension is approximately the height of the value in the Time
field.3.12.151.153