User Manual

Getting Started

UI Anchor Assistant — Unity uGUI

UI Anchor Assistant is an editor and runtime utility for Unity uGUI that helps automate the initial setup of UI. This makes it easier to support various screen resolutions, aspect ratios, and devices with notches or safe areas.

[!NOTE] This tool is a setup helper, not a complete responsive layout solution. Once this pipeline is executed, you will still need to manually adjust Layout Groups, element sizes, and spacing to match your design requirements.


Key Features

FeatureDescription
One-Click FixConfigures CanvasScaler, creates the SafeArea container, moves the UI elements, and executes the anchor fix sequentially with a single button click.
Anchor FixConverts pixel offsets to anchor positions based on world-space bounds. Full precision without snapping.
Target ScopeLimit the scope of the operation to the entire Canvas or only the currently selected object and its children.
Multi-Device Safe AreaThe SafeAreaFitter component reads Screen.safeArea from the OS every frame and automatically adjusts the container size.
Aspect Ratio ModesFour scaling modes via UIAnchorPreset: Fit, Expand, AutoMatch, and MaintainAspect.
Ready-Made Presets5 out-of-the-box presets: Portrait, Landscape, Tablet, Ultrawide, and Foldable.
Reference PPUSupports configuring Pixels Per Unit in presets to maintain sprite sharpness across different DPI values.
Ignore TaggingThe IgnoreUIAnchor component flags specific elements to bypass the anchor fix process.
Gizmo VisualizationColored borders in the Scene View display the effective SafeArea boundaries in real-time.

Editor Window Guide

Open the editor window via the Unity menu: Tools → QuickSetup → UI Anchor Assistant

1. Target Configuration

FieldDescription
Target CanvasThe root Canvas to be processed. If left blank, the system automatically detects it from the active object in the Hierarchy.
PresetA UIAnchorPreset ScriptableObject containing references for resolution, aspect ratio mode, PPU, and Safe Area configuration.
Target ScopeCanvas: Process the entire UI. Selection: Only process the selected object and its children.

2. Quick UI Optimization (One-Click)

The OPTIMIZE & FIX MY UI button runs the entire sequence of fixes in order:

  1. Sets up the CanvasScaler according to the preset settings.
  2. Creates a SafeArea GameObject to act as the main container.
  3. Moves all UI elements inside the SafeArea container.
  4. Performs anchor fixing on all UI elements (optional, controlled via toggle).
  5. Automatically applies safe area boundaries from the OS.

[!IMPORTANT] All actions performed in the editor window support Unity’s built-in Undo / Redo (Ctrl + Z / Ctrl + Y).

3. Individual Utilities

ButtonDescription
Setup Canvas ScalerConfigures only the CanvasScaler without modifying anchors or the SafeArea.
Apply Anchor FixConverts pixel offsets to anchors based on world-space position. Full precision, no snapping.
Add Safe Area FitterAdds or updates only the SafeArea container without processing other anchors.

Presets (UIAnchorPreset)

A Preset is a ScriptableObject that stores all UI scaling configurations. There are 5 built-in presets:

PresetReference ResolutionAspect ModeNotes
Portrait1080 × 1920AutoMatchDefault mobile portrait
Landscape1920 × 1080AutoMatchDefault mobile landscape
TabletPreset1668 × 2388ExpandiPad Pro — prevents content clipping
UltrawidePreset2560 × 1080MaintainAspect21:9 monitors with pillarbox styling
FoldablePreset1768 × 2208AutoMatchUnfolded foldable screen (Galaxy Z Fold)

Preset Fields

FieldTypeDescription
Reference ResolutionVector2The reference design size of the canvas (e.g., 1080 × 1920).
Reference Pixels Per UnitfloatPixels Per Unit for sprites on the Canvas. Default: 100.
Aspect ModeenumSee the Aspect Ratio Modes section below.
Enable Safe AreaboolEnables Safe Area support when executing the One-Click Fix.
Match AxisfloatUsed only for the Fit mode. 0 = Width, 1 = Height.

Aspect Ratio Modes (AspectMode)

Fit

Uses the standard Match Width or Height mode on the CanvasScaler with a manual Match Axis slider.

Expand

The canvas expands outward to prevent text or elements from clipping. Ideal for main menus.

AutoMatch

Dynamically detects the device aspect ratio at runtime:

  • Wider screens (Landscape / Tablet) → matches Height (1.0)
  • Taller screens (Portrait) → matches Width (0.0)

Helps prevent buttons or panels from shrinking excessively on devices with unusual aspect ratios.

MaintainAspect

Locks the aspect ratio precisely to the preset’s reference resolution (e.g., pure 9:16 or 16:9).

  • Uses mathematical bounds directly on the SafeArea for a letterbox/pillarbox effect.
  • Aligned within the safe area boundaries — the main UI is not cut off by notches, nor does it stretch abnormally.

Runtime Components

SafeAreaFitter

Attached to the SafeArea container. The [ExecuteAlways] attribute enables it to work in both Edit Mode & Play Mode.

Inspector Sections:

  • Configuration — Preset slot that can be replaced dynamically via script.
  • Gizmo Visualization — Toggle visibility, border color, and Line Thickness (slider 1–10).
  • UtilitiesForce Apply Safe Area and Reset to Full Screen buttons.
// Change preset at runtime
GetComponent<SafeAreaFitter>().Preset = myNewPreset;

// Manually re-apply safe area
GetComponent<SafeAreaFitter>().ApplySafeArea();

// Reset size to full screen
GetComponent<SafeAreaFitter>().ResetToFullScreen();

How Safe Area works:

Screen.safeArea (from OS)

Normalized to (0.0 – 1.0) relative to screen

Set to RectTransform.anchorMin / anchorMax

SafeArea container adjusts its size

All child UI elements adjust accordingly

Re-application only occurs if the Screen.safeArea value changes (e.g., screen rotation, split-screen, etc.).


IgnoreUIAnchor

Attach this component to elements that should be bypassed by the anchor fix calculation.

FieldDescription
ignoreChildrenIf enabled, all children under this object will also be skipped. Default: true.

Common use cases:

  • Fullscreen background images (must cover the entire screen including the notch area)
  • Close / Back buttons that already have precise, manual anchoring
  • Overlay effects that are intended to extend beyond the Safe Area

Class & Asset List

NameTypeDescription
UIAnchorAssistantWindowEditorWindowThe main editor window for this tool.
UIAnchorFixerstatic classAnchor calculation logic (Exact Bounds via world-space).
SafeAreaFitterMonoBehaviourRuntime component managing the Safe Area & CanvasScaler.
UIAnchorPresetScriptableObjectConfig asset for resolution, PPU & aspect ratio mode.
IgnoreUIAnchorMonoBehaviourUtility component to exclude an object from auto-calculations.
AspectModeenumFit, Expand, MaintainAspect, AutoMatch.
SafeAreaFitterEditorEditorCustom Inspector for SafeAreaFitter.
IgnoreUIAnchorEditorEditorCustom Inspector for IgnoreUIAnchor.
UIAnchorPresetEditorEditorCustom Inspector for UIAnchorPreset.

Usage Notes

  1. Preset Resolution Orientation — Ensure that the reference resolution orientation matches your target display layout:

    • 1080 × 1920 for portrait games.
    • 1920 × 1080 for landscape games.
    • An inverted orientation will cause the Canvas to shrink drastically.
  2. Fullscreen Backgrounds — Place background images directly as children of the Canvas (not inside the SafeArea) and add the IgnoreUIAnchor component. This ensures the background covers the entire screen (including the notch), while UI/HUD elements remain safely inside the SafeArea.

  3. Layout Groups — Elements controlled by a HorizontalLayoutGroup, VerticalLayoutGroup, or GridLayoutGroup are automatically bypassed since their positions are managed entirely by Unity’s layout system. The tool will not alter them.

  4. Anchor Fix — Anchor calculation uses GetWorldCorners() to read the actual world space positions before the anchors are modified. This ensures consistent results even when CanvasScaler scaling is active.

  5. Device Simulator — In the Unity Editor, Screen.safeArea always returns the full screen dimensions as monitors don’t have notches. Use Window → General → Device Simulator to preview the safe area for real-world device profiles (e.g., iPhone, Samsung).

  6. Reference PPU — Align the Reference Pixels Per Unit in the preset with the PPU of your sprites to prevent size discrepancies between the Editor and target devices.