Scaling UI for all your player’s devices is essential to a smooth game experience. Misscaling UI can lead to an unprofessional look, and worse, unplayability. Unfortunately, most new developers faced with this issue hear the ill-advised, “just use the scale property.” This advice inevitably leads them to only using scale for everything, thinking it works for a while, then confusion after it sort of, but not really, works.
So what’s the secret?
Use UILayouts!
UILayouts are built-in instances that you can use to control your UI. They are incredibly useful and easily customizable.
There are many helpful UILayouts, and I invite you to play with all of them, but for the sake of this tutorial, I’ll be focusing on three that massively help scaling.
UIAspectRatioConstraint
UIAspectRatioConstraint allows you to enforce a ratio for a specific UI. Be rest assured that your square is indeed a square. Divide your UI’s AbsoluteSize.X by its AbsoluteSize.Y to calculate a ratio.
UIGridLayout
UIGridLayout allows you to easily create equally sized, evenly spaced, and nicely formatted grids and lists of UI elements. UIListLayout and UITableLayout are similar but have slightly different properties.
UISizeConstraint
UISizeConstraint allows you to control the minimum or maximum size of a UI. Ever set a UI’s scale to 0.1, only to find out it results in a 3 pixel UI while on mobile? No longer! UITextSizeConstraint is the same, but for text.
In the end, scaling your UI for all devices and understanding all of Studio’s UILayouts is a hassle for anyone new to Studio UI creation. (I’ve been doing it for a year and it’s still a pain…) But as you make more and more UI, you’ll find it becomes second nature to design your UI around scalability. Until then, practice, practice, practice!
Use AnchorPoint
So you’ve scaled your UI nicely, but it won’t stay where you want it to. Let me introduce you to AnchorPoint. This wonderful property allows you to definitively set the position of a UI object relative to its parent UI object/viewport based on its Position.X/Y.Scale. Want something perfectly centered? Set AnchorPoint to (0.5, 0.5) and the scale position to (0.5, 0.5). Want it in the bottom right? AnchorPoint (1, 1) and position (1, 1).