๐ผ๏ธ Lesson 4.1: Canvas Render Modes & Scaling
In Fundamentals you dropped a Canvas into a scene, added some text and a button, and it worked. But it probably looked wrong the moment you resized the Game view or ran it on a phone. This lesson fixes that for good: you'll learn the three render modes a Canvas can use, and how the Canvas Scaler plus anchors keep your UI sharp and correctly placed on every screen.
๐ฏ Learning Objectives
By the end of this lesson, you will be able to:
- Explain the three Canvas render modes and when to reach for each
- Configure the Canvas Scaler with Scale With Screen Size, a reference resolution, and the Match slider
- Choose a sensible reference resolution for your target platform
- Use anchors and pivots so elements reflow instead of drifting off screen
- Diagnose the "my UI is huge / tiny / clipped" problems every beginner hits
Estimated Time: 35 minutes ยท Prerequisite: Fundamentals UI (a basic Canvas with text and buttons)
In This Lesson
A Quick Canvas Recap
Every piece of UI in Unity lives under a Canvas โ the root object that actually draws your buttons, text, and images. When you create your first UI element from GameObject โธ UI โธ Button, Unity auto-creates a Canvas and an EventSystem for you. So far, so Fundamentals.
What Fundamentals glossed over is that a Canvas has a Render Mode setting at the very top of its Inspector, and that setting changes everything about how your UI is drawn, sized, and positioned. Get it right and your interface looks deliberate on a 4K monitor and a phone alike. Get it wrong and your buttons spill off the edge the first time someone resizes the window.
๐ Definition
Canvas: the component that gathers all child UI elements and renders them together in one batch. It defines the coordinate space your UI lives in and, via its Render Mode, whether that space is glued to the screen, rendered by a camera, or placed out in the 3D world.
The Three Render Modes
The Render Mode dropdown offers three choices. Here they are side by side โ how each one relates the Canvas to the screen and the world:
Screen Space - Overlay (the default)
The Canvas is rendered on top of everything the cameras draw, always filling the screen. It needs no camera reference and it's the simplest option. This is your go-to for classic 2D interface: menus, HUDs, dialogs. The one limitation is that nothing in the 3D scene can ever appear in front of Overlay UI โ it is literally the last thing drawn.
Screen Space - Camera
The Canvas is placed a set distance in front of a specific Render Camera (you drag the camera into the field). Because it now lives at a real depth, 3D objects and post-processing (bloom, a blur, particles) can render in front of or behind it, and perspective can subtly affect it. Reach for this when you want UI that interacts with camera effects, or a slight 3D tilt on your menus.
World Space
The Canvas becomes an ordinary object in the 3D world with a real position, rotation, and physical size in meters. Walk around it, stand behind it, or attach it above a character's head. This is how you build in-world screens (a terminal on a wall) and the floating nameplates and damage numbers we build at the end of this module.
โ Pro Tip
Keep your always-on-screen UI (HUD, menus, pause) on one Overlay canvas, and put any world-anchored UI (nameplates, interaction prompts) on separate World Space canvases. Mixing the two on one Canvas is impossible anyway โ render mode is set per Canvas โ so plan for multiple canvases from the start.
The Canvas Scaler
Here's the problem the Canvas Scaler solves. By default a Canvas measures everything in pixels. A button 200 pixels wide looks reasonable on a 1920ร1080 monitor, but on a 3840ร2160 screen it's now half the physical size โ tiny. And on a small window it might overflow. You do not want to hand-tune sizes per device.
The Canvas Scaler component (already on every Canvas you create) fixes this. Its most important setting is the UI Scale Mode dropdown. Here is the component as it appears in the Inspector, set the way you'll want it 90% of the time:
The three UI Scale Modes are:
- Constant Pixel Size โ elements keep their pixel size no matter the screen. This is the default and the cause of most "my UI is tiny on 4K" complaints. Rarely what you want.
- Scale With Screen Size โ you design against a reference resolution, and Unity scales the whole canvas up or down to fit the real screen. This is what you want almost always.
- Constant Physical Size โ elements keep a real-world size (millimeters/points) using the device DPI. Useful for touch targets on mobile.
โ ๏ธ The number-one UI beginner bug
If your interface looks perfect in the editor but comes out huge or microscopic in a build (or when you change the Game view resolution), the Canvas Scaler is almost certainly still on Constant Pixel Size. Switch it to Scale With Screen Size and set a reference resolution before you build anything real.
Choosing a Reference Resolution
The Reference Resolution is the canvas you pretend you're designing for. Unity then scales from it to whatever the player actually has. Good defaults:
- 1920 ร 1080 โ the safe default for PC and console games. Most desktops are at or below it, and it scales cleanly.
- 1080 ร 1920 โ portrait mobile.
- 2340 ร 1080 (or similar) โ modern landscape mobile.
The Match slider decides how Unity handles screens whose aspect ratio differs from your reference. At 0 it matches width (UI scales with horizontal size); at 1 it matches height; at 0.5 it splits the difference. For games that must run both wider and taller than the reference, 0.5 is a sane starting point.
๐ก Match by the axis that matters. For a landscape game where the play area's height is sacred (a side-scroller), push Match toward 1 (Height) so the UI never grows past the top and bottom. For a portrait game, push toward 0 (Width). Only fall back to 0.5 when neither axis is clearly more important.
Anchors & Pivots for Responsive Layout
The Canvas Scaler handles overall size. Anchors handle position โ where each element sticks when the canvas changes shape. You saw the Anchor Presets widget in Fundamentals (the little grid in the top-left of the RectTransform). Here's what it actually means.
Every UI element's RectTransform has four anchor handles that reference a point (or region) of its parent. The element's position is measured relative to those anchors, not to the screen origin. So if you anchor a health bar to the top-left corner, it stays pinned there no matter how wide the screen gets. Anchor a quit button to the bottom-right and it hugs that corner forever.
- Anchor to a corner (all four handles together in one spot) โ the element keeps a fixed size and sticks to that corner. Perfect for HUD elements.
- Stretch anchors (handles pulled apart) โ the element resizes with its parent. Perfect for a full-width top bar or a background that must fill the screen.
- Pivot โ the element's own reference point (0โ1 on each axis) that position and rotation are measured from. A pivot of (0.5, 0.5) means "position and rotate around my center"; (0, 1) means "around my top-left corner."
The rule of thumb, visualized:
element live?"] --> B{"Fixed size, pinned
to an edge/corner?"} B -- "Yes" --> C["Anchor to that
corner or edge"] B -- "No, it should
grow with the screen" --> D["Use stretch anchors
on that axis"] C --> E["Set pivot to the same
corner for clean offsets"] D --> F["Set left/right (or top/bottom)
padding via the RectTransform"]
Figure 3: Deciding between corner anchors and stretch anchors for each UI element.
โ Pro Tip
Hold Shift while clicking an Anchor Preset to move the pivot to match, and Alt to also snap the element's position to that anchor. Shift+Alt+click does both at once โ the fastest way to correctly pin an element to a corner.
โ ๏ธ Anchored to center, surprised it drifts
New UI defaults to center-ish anchors. On a wider screen, a "center" element stays centered โ which looks fine โ but a button you meant to keep in the corner will float toward the middle as the screen grows. If something drifts when you resize the Game view, its anchors are almost always the cause, not its position value.
Hands-on Challenge
๐๏ธ Exercise 1: Make a resolution-proof HUD frame
Objective: Build a Canvas whose corners stay put at any resolution.
- Create a UI Canvas. On its Canvas Scaler, set UI Scale Mode to Scale With Screen Size, reference resolution 1920 ร 1080, Match 0.5.
- Add a Text element, anchor it top-left (Shift+Alt+click the preset), and label it "Score: 0".
- Add a Button, anchor it bottom-right, label it "Pause".
- In the Game view, switch the resolution dropdown between 1920ร1080, 1280ร720, and a portrait size. Watch the elements stay glued to their corners.
๐ก Hint: my elements move to the middle when I resize
Their anchors are still centered. Select each element, open the Anchor Presets grid in the RectTransform, and Shift+Alt+click the correct corner. Anchoring โ not the position numbers โ is what pins them.
โ Success check
At every resolution you try, "Score" hugs the top-left and "Pause" hugs the bottom-right, both staying a sensible size relative to the screen rather than shrinking to dots or ballooning.
๐๏ธ Exercise 2: Compare render modes
Duplicate your Canvas and set the copy's Render Mode to World Space. Give it a RectTransform scale of about 0.01 on each axis and place it a couple of meters in front of your Main Camera. Move the Scene camera around it and notice how it now behaves like a physical object you can view from an angle โ the exact behavior we'll exploit for nameplates in Lesson 4.4.
๐ฏ Quick Quiz
Question 1: Your menu looks perfect in the editor but is tiny in the built game on a 4K display. What's the most likely fix?
Question 2: You want a health bar that always stays glued to the top-left corner, same size, on any screen. What should you do?
Question 3: Which render mode lets 3D objects and post-processing appear in front of your UI?
Summary
๐ Key Takeaways
- A Canvas's Render Mode is the first decision: Overlay (flat on screen), Camera (a set distance in front of a camera), or World Space (a physical object in the scene).
- The Canvas Scaler should almost always be Scale With Screen Size with a sensible reference resolution (1920ร1080 for PC).
- The Match slider chooses whether width or height drives scaling on off-aspect screens.
- Anchors pin position: corner anchors keep a fixed size stuck to an edge; stretch anchors resize with the parent.
- The pivot is the element's own reference point for position and rotation.
- UI that "drifts" or "shrinks" is nearly always an anchor or Canvas Scaler problem, not a position-number problem.
๐ What's Next?
Now that your UI scales and anchors correctly, it's time to build the interfaces players actually touch first. In Lesson 4.2: Main Menu & Pause System you'll assemble a proper main menu, a pause overlay, and wire up Time.timeScale to freeze the game โ handling the pause action through the new Input System you learned in Module 3.
๐ผ๏ธ Your UI is now display-proof
Render mode, Canvas Scaler, anchors, pivots โ these four dials decide whether your interface looks intentional everywhere or breaks the moment it leaves your monitor. You've got them.