Search Unity

Idiomatic Unity approach to Canvas blocking editing your scene

Discussion in 'Unity UI (uGUI) & TextMesh Pro' started by AP124526435, Sep 10, 2019.

  1. AP124526435

    AP124526435

    Joined:
    Aug 19, 2019
    Posts:
    2
    I started building a scene at 0,0,0. I added a canvas. To the canvas I have now added a border of buttons. These overlap with my scene preventing me from interacting with it.

    I have one of three options, none of them seem very smart and I'm wondering if there's a better idomatic Unity approach?

    1. Manually disable and re-enable the canvas every time I want to edit my scene.
    2. Disable all the canvas elements that are currently overlapping my scene and add a script that on start, re-enables them using .SetActive(true). This isn't too bad as I can put everything inside an object whose sole job is to be inactive until the game is running (unless I need to edit them in which case there's only one check box I need to toggle).
    3. Move my whole scene down by 100 (wish I had known this at the start)
    4. Move the canvas (not possible)
    Thoughts welcome. How do other people deal with this?
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    4,214
    I deal with it by having all the UI elements on a UI layer, and then have visibility for that layer toggled off - you can do that in the upper-right corner of the editor in the "Layers" dropdown.

    I've also set that up with a little shortcut, so ctrl+U toggles between UI mode and normal mode:

    Code (csharp):
    1. // This goes in an editor folder or editor-only asmdef
    2. public static class EditorCommands {
    3.     [MenuItem("Commands/Toggle UI Layer")]
    4.     public static void ToggleUILayers() {
    5.         var uiLayer = LayerMask.GetMask("UI");
    6.  
    7.         if (Tools.visibleLayers != uiLayer)
    8.             Tools.visibleLayers = uiLayer;
    9.         else
    10.             Tools.visibleLayers = ~uiLayer;
    11.     }
    12. }
     
    Last edited: Sep 10, 2019
  3. AP124526435

    AP124526435

    Joined:
    Aug 19, 2019
    Posts:
    2
    Thank you. This is significantly better.

    I had to make a minor change to the
    ~uiLayer & ~Layer.Mask.Map;
    part as I couldn't find
    Layer
    :

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3.  
    4. public static class EditorCommands
    5. {
    6.     [MenuItem("Commands/Toggle UI Layer")]
    7.     public static void ToggleUILayers()
    8.     {
    9.         var uiLayer = LayerMask.GetMask("UI");
    10.  
    11.         if (Tools.visibleLayers != uiLayer)
    12.             Tools.visibleLayers = uiLayer;
    13.         else
    14.             Tools.visibleLayers = ~uiLayer;
    15.     }
    16. }
    17.  
     
  4. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    4,214
    Whoops, I thought I had modified my example to work, missed some of it. We've got a map layer that we never want to see for... reasons, so that's expluded there. I updated my post.