Search Unity

Official Overlays Developer Guide

Discussion in 'Editor Workflows' started by gabrielw_unity, Dec 8, 2020.

  1. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,334
    Oh, right.

    @gabrielw_unity, GameView being internal is an insane pain point for a ton of reasons. We can't use overlays with it. We can't find it in order to dock other windows next to it. We can't re-dock it somewhere else. We can't set the gameView vSync value from script. We can't toggle gizmos from script. There's a bunch of other things.

    It's yet another one of those cases where Unity's being overly conservative with what to enable users to do, to the detriment of the users.
     
    khan-amil likes this.
  2. kaarrrllll

    kaarrrllll

    Unity Technologies

    Joined:
    Aug 24, 2017
    Posts:
    552
    Editor windows must opt-in to Overlay support. https://docs.unity3d.com/2023.1/Documentation/ScriptReference/Overlays.ISupportsOverlays.html

    The only built-in window that is opting in currently is the Scene View. In the future this might be relaxed, but in the interest of landing the feature we felt it was the right decision to limit the scope in order to be certain that there were no unintended side effects.
     
  3. GamerXP

    GamerXP

    Joined:
    Mar 22, 2014
    Posts:
    78
    So I thought. But.. what about main toolbar? I think that I saw you being able to DnD tools from here in early videos, but it seems to be fully fixed now.
     
  4. Khaeops

    Khaeops

    Joined:
    Dec 28, 2014
    Posts:
    31
    What's the workflow for styling the overlay elements? I want to move the positions of my elements but it seems that they are automatically set and I can only register what elements exist. I would like to make a toggle checkbox above a dropdown, but all I can get is a toggle button instead and it always places beside my dropdown rather than above or below.

    upload_2022-9-21_10-31-2.png

    When I override CreatePanelContent(), it places them above, but I can't figure out how to add a space between elements, and my dropdown renders the arrow on a new line.

    upload_2022-9-21_10-32-53.png

    Should I be using the Overlays IMGUI support instead, and is there a guide somewhere I can follow for it?
     
  5. Robin_Roekens

    Robin_Roekens

    Joined:
    Apr 22, 2022
    Posts:
    1
    Hello @gabrielw_unity ,

    I'm working on a custom Overlay and I can only implement the CreatePanelContent method not CreateHorizontalToolbarContent nor CreateVerticalToolbarContent.
    After closer inspection the ToolbarOverlay class I use for inheritance, it has an implementation of the 2 methods but they aren't virtual.
    And the 2 interfaces required to implement those in another class, ICreateHorizontalToolbar and ICreateVerticalToolbar, are internal.

    Am I missing something regarding the implementation of those methods?
     
  6. RedGlow82

    RedGlow82

    Joined:
    Nov 22, 2013
    Posts:
    8
    Is there a simple workflow to use uxml/uss with overlays? I noticed you can't assign uxml to public VisualTreeAsset properties directly in the defaultReferences from the interface like you can do with EditorWindow, and UI Toolkit Live Reload does not influence the reloading of overlay windows built this way (I guess the two problems may be connected?). In fact, I guess the only way to force the reloading of an Overlay window while developing is to force code re-compilation, right?
     
  7. gabrielw_unity

    gabrielw_unity

    Unity Technologies

    Joined:
    Feb 19, 2018
    Posts:
    963
    Sorry, you'll want to poke at @kaarrrllll for the code stuff :D
     
  8. sevelee

    sevelee

    Joined:
    Apr 5, 2017
    Posts:
    25
    It's possible to set default visibiliy now? I set displayed to true in constructor of my toolbar overlay but it not works.
     
    pokelocos likes this.
  9. kaarrrllll

    kaarrrllll

    Unity Technologies

    Joined:
    Aug 24, 2017
    Posts:
    552
  10. Saniell

    Saniell

    Joined:
    Oct 24, 2015
    Posts:
    193
    Is it possible to specify default docking of an overlay?

    Also I'd like to know if its possible to make overlay resizable by user somehow? I think custom tools for editing would benefit from it. Like if overlay contains "brush settings" for some painting tool
     
  11. kaarrrllll

    kaarrrllll

    Unity Technologies

    Joined:
    Aug 24, 2017
    Posts:
    552
    Yes, although not in 2021.3. See https://docs.unity3d.com/2023.1/Documentation/ScriptReference/Overlays.OverlayAttribute.html

    Likewise, Overlay resizing was added recently (I believe 2022.2, but I'm not certain).
     
    Saniell likes this.
  12. Saniell

    Saniell

    Joined:
    Oct 24, 2015
    Posts:
    193
    That's nice to know, thanks. Though I can't seem to find much about resizing in docs except size property. To be clear, by resizing I meant allow user to change size of an overlay same way we can drag windows around. Am I missing something or is it not supported at the moment?
     
  13. antoinebr_unity

    antoinebr_unity

    Unity Technologies

    Joined:
    Nov 16, 2018
    Posts:
    23
    Resizing is currently opt-in by setting the minSize and maxSize when the overlay is constructed. Note that these values aren't persistent and must be set every time the overlay is created but the size itself is persistent.

    Here's the API documentation for that:
    https://docs.unity3d.com/2023.1/Documentation/ScriptReference/Overlays.Overlay-minSize.html
    https://docs.unity3d.com/2023.1/Documentation/ScriptReference/Overlays.Overlay-maxSize.html

    And here's a code exemple:
    Code (CSharp):
    1. using UnityEditor.Overlays;
    2. using UnityEngine.UIElements;
    3. using UnityEngine;
    4. using UnityEditor;
    5.  
    6. [Overlay(typeof(SceneView), "Test")]
    7. public class OverlayTest : Overlay
    8. {
    9.     public OverlayTest()
    10.     {
    11.         minSize = new Vector2(0, 0);
    12.         maxSize = new Vector2(500, 500);
    13.     }
    14.  
    15.     public override VisualElement CreatePanelContent()
    16.     {
    17.         return new VisualElement();
    18.     }
    19. }
     
  14. khan-amil

    khan-amil

    Joined:
    Mar 29, 2012
    Posts:
    206
    Any improvement on this side to expect ? I wanted to support some of our runtime tools with an overlay to limit the amount of windows our team has to maintain and open, but I'll have to switch back to that.
     
  15. kaarrrllll

    kaarrrllll

    Unity Technologies

    Joined:
    Aug 24, 2017
    Posts:
    552
    @khan-amil if you have specific windows in mind that would benefit from overlay support please let me know. There isn't much movement on relaxing this restriction because so far no-one has asked for it (except you!).
     
  16. khan-amil

    khan-amil

    Joined:
    Mar 29, 2012
    Posts:
    206
    Well as was said above by a couple of users, it would be nice to have the Game window accepting the overlays.
    My use case was to add something in the editor-side for a runtime tool. Our level designers mainly work in the Game window, so adding stuff in there would be great.
     
  17. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    934
    How can I add overlays as you have for Box colliders and other systems appearing inside the Tools overlay window?
    upload_2023-2-6_0-37-1.png
    I have a vector3 Property for my custom component for which I want to implement a scene handle for controlling it.
     
  18. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,334
    I'm pretty sure that's an EditorTool you're looking at, so you'd have to implement one of those for your custom component.
     
    Ruchir likes this.
  19. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    934
    That worked, Thanks.

    I have one more question, How do I add multiple buttons/Toggles to my editor tools, right now I only have one Toggle
    upload_2023-2-6_17-30-2.png
    Also, how do I change the "Sp" to an Icon, using the Icon attribute changed the button's icon and not the header attribute Like:
    upload_2023-2-6_17-31-19.png
     

    Attached Files:

  20. webik150

    webik150

    Joined:
    Mar 23, 2013
    Posts:
    62
    Any easy way to get the overlay's current width?
     
  21. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,890
    What's the recommended way of adding a RadioButton group to an overlay toolbar (in 2022.2)?

    Something that works like the "Tools" toolbar where you can only have one of the Move, Rotate, Scale etc tools selected. If that code is in a package or on github I'd appreciate a pointer.
     
  22. cvbattum

    cvbattum

    Joined:
    Apr 20, 2018
    Posts:
    12
    Being able to assign
    VisualTreeAsset
    to serialized properties on Overlays feels like a huge missing feature. Will this be added in some way soon? And what is the recommended workaround? LoadAssetAtPath feels painfully hardcoded...
     
  23. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,273
    What is the key bind for the overlay menu?

    The documentation says this:
    1. In the Scene view, press the ` key to display the Overlays menu.
    But how is that in non-US keyboards? The US keyboards are the only ones who support the key directly and it's been annoying ever since id software use that for their in-game console, ie decades ago.
     
  24. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,334
    I'm pretty sure it's spacebar? Or did they change it for 2022?
     
  25. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,273
    It's not spacebar anymore
     
  26. JesOb

    JesOb

    Joined:
    Sep 3, 2012
    Posts:
    1,109
    Please add overlay to inspector

    Actually we need only horizontal toolbar on top of it so we can add custom buttons and data in it
     
    Ruchir likes this.
  27. oscarAbraham

    oscarAbraham

    Joined:
    Jan 7, 2013
    Posts:
    431
    Hi, this isn't the same, but it might help you. It let's you add stuff with IMGUI to the inspector's header: finishedDefaultHeaderGUI.
     
    Ruchir and JesOb like this.
  28. fleity

    fleity

    Joined:
    Oct 13, 2015
    Posts:
    345
    I wanted an overlay with a transparent background similar to the orientation overlay in the top right corner. I struggled for a bit with getting access to the correct visual element because in CreatePanelContent the root visual container for the overlay is not attached to any other visual element yet.
    But you can get there using the OnGeometryChanged event!

    (just as a quick extracted example: )

    Code (CSharp):
    1.  
    2. private VisualElement root;
    3.  
    4. public override VisualElement CreatePanelContent()
    5.     {
    6.         root = new VisualElement() { name = "My Panel Root" };
    7.         root.Add(new Label() { text = "Hello" });
    8.         root.RegisterCallback<GeometryChangedEvent>(OnGeometryChanged);      
    9.         return root;
    10.     }
    11.  
    12. private void OnGeometryChanged(GeometryChangedEvent evt)
    13.     {
    14. VisualElement overlayContainer = root.parent.parent;
    15. overlayContainer.style.backgroundColor = new StyleColor(new Color(0, 0, 0, 0.1f));
    16. root.UnregisterCallback<GeometryChangedEvent>(OnGeometryChanged);
    17.     }
    have fun
     
    Ruchir likes this.
  29. fleity

    fleity

    Joined:
    Oct 13, 2015
    Posts:
    345
    Does anyone know how to set the docked state and position for an overlay from c#?

    I've added a simple button to an overlay, while the click callback works, the visual change does not happen. Confusingly the debugger shows the state change. What is going on?!

    overlay_button.gif

    --> i figured out why it isn't working technically but I don't get the decision why it should be behaving this way.
    there are two style class references for the button in the overlay
    .unity-button and .unity-overlay .unity-button

    the second one which selects buttons inside the overlay overwrites border width and background color and therefore prevents any hover and active pseudo states.. why? because we should use EditorToolbarButton instead of Button? Those look a bit different but apart from that work (and the different style can be fixed with AddToClassList("unity-button").

    upload_2023-11-10_18-34-17.png upload_2023-11-10_18-36-41.png
     
    Last edited: Nov 10, 2023
  30. GamerXP

    GamerXP

    Joined:
    Mar 22, 2014
    Posts:
    78
    How to make custom overlay be shown in ScreneView by default? "Default Display" in OverlayAttribute does nothing.

    Code (CSharp):
    1.     [UnityEditor.Overlays.Overlay(typeof(SceneView), id, "GameCamera Tools", id, true)]
    2.     class GameCameraToolbar : UnityEditor.Overlays.ToolbarOverlay
    3.     {
    4.         const string id = "game-camera-overlay";
    5.  
    6.         public GameCameraToolbar() : base(CameraFullResetButton.id, CameraRotationResetButton.id)
    7.         {
    8.            
    9.         }
    10.     }
    Using Unity 2021.3.33f
     
  31. fleity

    fleity

    Joined:
    Oct 13, 2015
    Posts:
    345
    Maybe you could try sth with the InitializeOnLoad attribute and set the overlay visible for all open scene views in the constructor, probably with editor prefs as backing field for if it should be shown.. how these kind of displays were done before overlays but the default display attribute worked for me in 2022.3. Is it possible that the display value gets serialized when the class is compiled for the first time and set to false if the attribute wasn't present then? Have you tried renaming the file and the class?
     
  32. GamerXP

    GamerXP

    Joined:
    Mar 22, 2014
    Posts:
    78
    I have this class around for a long time in multiple project, and it never displayed by default in any projects on any PC. I assume it's a bug.

    InitializeOnLoad though. Well, I guess I can give it a try. Not sure if stuff I need is internal or not though.