askvity

How do I Edit Canvas in Unity?

Published in Unity UI Editing 4 mins read

To edit a Canvas in Unity, you generally use the Unity editor interface, specifically by selecting the canvas element within your project and then modifying its properties in the inspector panel.

Here's a breakdown of the process:

Accessing the Canvas

  1. Locate the Canvas: In the Unity editor, navigate to the Hierarchy window. This window displays all the objects in your current scene.
  2. Select the Canvas Object: Look for the game object that represents your canvas. It's typically named "Canvas" by default, but it might have a custom name. Click on it to select it.

Editing Canvas Properties in the Inspector

Once you have selected the Canvas game object:

  1. Open the Inspector Panel: On the right side of the Unity editor, the Inspector panel should now display the properties of the selected Canvas.

  2. Modify Settings: In the Inspector, you will find various parameters that control the behavior and appearance of the Canvas. These are organized into different components attached to the canvas object:

    • Canvas Component:

      • Render Mode: This allows you to choose how the canvas renders (e.g. Screen Space - Overlay, Screen Space - Camera, World Space).
      • Pixel Perfect: Renders the Canvas elements pixel perfect, making them appear crisp.
      • Sorting Layers: Changes the order the canvas is drawn at.
      • Additional Shader Channels: Additional channels the shader can use.
      • Sorting Order: Changes the sorting order of multiple canvases on the same layer.
    • Canvas Scaler:

      • UI Scale Mode: Dictates how to scale UI elements on the canvas.
      • Scale With Screen Size: Allows UI to scale based on the screen size.
      • Reference Resolution: When scaling based on the screen size, the canvas is designed around this resolution.
    • Graphics Raycaster:

      • Blocking Masks: Allows the ability to specify layers which should cause the graphics raycaster to fail.

      • Blocking Objects: Allows the ability to specify UI elements which should cause the graphics raycaster to fail.

      • Ignore Reversed Graphics: Prevents clicking on graphics that are behind the current object.

  3. Apply Changes: Any adjustments you make in the Inspector are applied immediately in the scene and game view.

Editing Canvas Settings in the UI Builder

According to the reference provided:

  • Select UXML: In the Hierarchy view, find and select your UI document (UXML file).
  • Modify Settings in Inspector: Once selected, the Inspector will allow you to change Canvas settings.

Practical Insights

  • Different Render Modes: Choose the correct render mode based on your game's needs. Screen Space - Overlay is great for UI that always appears on top, while World Space lets you integrate the UI into the 3D world.
  • Scale Considerations: Carefully choose how your UI scales to prevent overlapping or clipping, especially if you plan for different screen resolutions.
  • Parenting: The canvas is the parent of all UI elements. When you select elements under the canvas, you will be able to further modify them within the inspector.

By using the Hierarchy to select the canvas and the Inspector to modify its settings, you have full control over how your canvas functions and renders within your Unity project. You can also edit your canvas' settings by selecting its corresponding UXML file in the Hierarchy within UI Builder.

Related Articles