UnityRef is currently in early development. Some features may be incomplete and/or not functioning.

UNITYREF

Your Pit Stop For Solving ANYTHING in Unity

ui

[UI] Fix Canvas Prefab Offset and Locked Transform Issues

Solution

prefabstransformCanvas

Unity 2021.x - Unity 6.3.x

Published Tue, Mar 24

Issue

 A Canvas prefab does not maintain its original placement when instantiated or viewed, and its RectTransform properties appear locked or non-interactable, preventing manual repositioning within the scene hierarchy.

Resolve Canvas prefab misplacement by calibrating the Canvas Scaler component. Misalignment is typically caused by a mismatch between the Reference Resolution and the target display aspect ratio.

Explanation

The root cause of Canvas prefab misplacement often lies in the Canvas Scaler component settings, specifically the Reference Resolution property. If the Reference Resolution is set to a fixed pixel value that does not align with the target aspect ratio, the UI elements may shift or scale incorrectly when the prefab is instantiated into a different scene context. Additionally, when the Render Mode is set to Screen Space - Overlay, the RectTransform values are automatically driven by the screen size, making them appear locked. 1. Select your Canvas prefab in the Project window. 2. Locate the Canvas Scaler component in the Inspector. 3. Update the Reference Resolution to match the target aspect ratio (e.g., 1920x1080 for 16:9). 4. Change the Screen Match Mode to Match Width Or Height and adjust the slider based on whether the UI should prioritize horizontal or vertical scaling. 5. If the RectTransform must be manually editable, change the Render Mode on the Canvas component to World Space or Screen Space - Camera. Additional Tips: * Verify that the Reference Resolution matches the resolution set in the Game View to ensure what you see in the editor persists in the build. * Use the Physical Size setting in the Canvas Scaler if you require consistent element sizing across high-DPI mobile devices. * Check if multiple Canvas components exist in the scene, as nested Canvas objects can inherit scaling logic from their parents, overriding the Reference Resolution.


Related Posts Haven't quite found a solution to your problem? We think these posts might help you.

Content inspired by a Unity discussion post.