0
\$\begingroup\$

In our workflow we use a Screen Space - Overlay canvas for UI. The only problem with it is that you can't change it's position (The values are driven by the Canvas component) and it's left-bottom corner is in the world position (0,0,0).

The issue it creates is that in the scene view we usually create the game objects around (0,0,0) (player, levels etc.) and because of the canvas sitting there, it most of the time blocks our mouse raycasts (we can't click on the world objects) - see below.

To be specific, I'm not talking about the Canvas blocking raycasts in Game View/Play Mode but in the Scene view in the editor:

enter image description here

When I click on the cube the overlay canvas captures my click and selects the canvas, not the cube. Because of that we have to make weird tricks (disabling the canvas manually when we build the levels etc.).

You can't change the component's position at all:

enter image description here

Is there any way to somehow move the Overlay Canvas away from (0,0,0) in the Scene View?

\$\endgroup\$

6 Answers 6

2
\$\begingroup\$

As an update to Jacob's answer, his code works correctly, but it sometimes appears to not work because you will only see the UI appear or disappear when the SceneView is redrawn (which may not happen by default). Here is a slightly improved version that includes a SceneView.RepaintAll() call to ask the Editor to repaint the SceneView whenever the UI Layer is toggled on or off. This script should be placed in a folder named Editor. The MenuItem attribute places this command at the bottom of the Window menu (so just below the UI Toolkit stuff).

using UnityEngine;
using UnityEditor;

static public class UILayerToggleClass {
    [MenuItem("Window/UI Layer Toggle", false, System.Int32.MaxValue)]
    static void UILayerToggle()
    {
        Tools.visibleLayers ^= 1 << LayerMask.NameToLayer("UI");
        SceneView.RepaintAll();
    }
}
\$\endgroup\$
1
\$\begingroup\$

No. It’s locked to the camera as that’s the function of screen space overlay. Create a child rectransform and use that rather as you can change its position.

\$\endgroup\$
1
\$\begingroup\$

Turns out it's not possible. I just created a workaround using the magical Layers menu in Unity (I had no idea such a thing exists):

[MenuItem("Zenith/Toggle UI Layers", false, 100)]
static void ToggleUILayers()
{
    Tools.visibleLayers ^= 1 << LayerMask.NameToLayer("UI");
}

The menu item above will toggle the entire UI on and off :)

enter image description here

\$\endgroup\$
1
\$\begingroup\$

On the left side of the Hierarchy window there are hand and eye icons (mouse over to see them). They do just that, enable/disable mouse select and visibility in scene view.

enter image description here

On the image game objects in the blue rect can not be selected with the mouse in scene view and the object in the red rect is not visible in scene view.

\$\endgroup\$
0
\$\begingroup\$

This is the easiest way ive found to implement a moveable overlay canvas:

  1. Create a new empty GameObject called "UI" (this is just a container for all your ui elements).

  2. Create a new camera called "UI Camera" nested under your "UI" GameObject.

  3. Nest your canvas under the "UI" GameObject element and set its "Render Mode" to "Screen Space - Camera" and its "Render Camera" to the "UI Camera" that you just created.

You should now be able to select the "UI" Game object and position it to move your canvas wherever you would like in the scene view.

\$\endgroup\$
-1
\$\begingroup\$

yes, it is possible to move Overlay Canvas away from (0,0,0) in the Scene View by adjusting its position property in the Transform component.

\$\endgroup\$
2
  • \$\begingroup\$ OP shows that these settings show as disabled in their inspector. Can you recommend a way to enable them? \$\endgroup\$
    – DMGregory
    Apr 22, 2023 at 12:38
  • \$\begingroup\$ Not to be that person, but... this answer doesn't sound very "human". \$\endgroup\$
    – liggiorgio
    Apr 24, 2023 at 11:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .