Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by JDatUnity · Jul 05, 2017 at 06:50 PM · guicustom editorsceneviewonscenegui

Always show Custom Editor GUI

I have a custom editor script with OnSceneGUI and some GUI labels and buttons which all work nicely. However when I select a different object in the scene the GUI is no longer visible. How can I keep it so the GUI is always visible on the sceneview?

Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RobAnthem · Jul 05, 2017 at 07:24 PM 1
Share

To do this, you need the script to be separate from any inspector and register the event to the OnSceneGUIDelegate callback. Like this.

 public class $$anonymous$$yCustomGUI
 {
     [$$anonymous$$enuItem("Tools/Show$$anonymous$$yCustomGUI")]
    public static void InitGUI()
    {
       $$anonymous$$yCustomGUI $$anonymous$$CG = new $$anonymous$$yCustomGUI();
       OnSceneGUIDelegate += $$anonymous$$CG.RenderSceneGUI;
    }
 
    public void RenderSceneGUI()
    {
       //Scene gui stuff
    }
 }
avatar image JDatUnity RobAnthem · Jul 06, 2017 at 12:59 PM 0
Share

This worked! Thank you so much!

I had to change a couple of things for it to work though:

 using UnityEditor;
 
 public class $$anonymous$$yCustomGUI {
     [$$anonymous$$enuItem("Tools/Show$$anonymous$$yCustomGUI")]
     public static void InitGUI() {
         $$anonymous$$yCustomGUI $$anonymous$$CG = new $$anonymous$$yCustomGUI();
         SceneView.onSceneGUIDelegate += $$anonymous$$CG.RenderSceneGUI;
     }
 
     public void RenderSceneGUI(SceneView sceneview) {
         //Scene gui stuff
     }
 }

avatar image JDatUnity RobAnthem · Jul 06, 2017 at 05:18 PM 0
Share

Just a quick follow up question: how can I reference an instance of a different editor script(with an OnInspectorGUI) to, for instance, use in the RenderSceneDelegate?

FindObjectOfType doesn't seem to work on editor scripts?

avatar image RobAnthem JDatUnity · Jul 06, 2017 at 06:42 PM 0
Share

Use singleton in the script you want to reference, so you can just access it like

 $$anonymous$$yCustomGUI.Instance.someField = this.someOtherField;

You could also pass an action from your inspector to your delegate script like this;

 public class $$anonymous$$yCustomGUI 
 {
     [$$anonymous$$enuItem("Tools/Show$$anonymous$$yCustomGUI")]
     public static void InitGUI() {
         SceneView.onSceneGUIDelegate += Instance.RenderSceneGUI;
     }
     public static $$anonymous$$yCustomGUI Instance;
     {
         get 
         {
             if (_instance == null)
             {
                 _instance = new $$anonymous$$yCustomGUI();
             }
             return _instance;
         }
         private set {_instance = value;}
     }
     private static $$anonymous$$yCustomGUI _instance
     private Action delegateAction;
     public void RegisterAction(Action action)
     {
         delegateAction = action;
     }
     public void RenderSceneGUI(SceneView sceneview) {
         if (delegateAction != null)
         {
                 delegateAction.Invoke();
         }
     }
 }
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by JDatUnity · Jul 06, 2017 at 01:00 PM

This is the answer, from the comments:

  using UnityEditor;
  
  public class MyCustomGUI {
      [MenuItem("Tools/ShowMyCustomGUI")]
      public static void InitGUI() {
          MyCustomGUI MCG = new MyCustomGUI();
          SceneView.onSceneGUIDelegate += MCG.RenderSceneGUI;
      }
  
      public void RenderSceneGUI(SceneView sceneview) {
          //Scene gui stuff
      }
  }
 



Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

106 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Custom Inspector - Update() alternative? 1 Answer

How To Drag Something From GUI - To Scene - Help 2 Answers

Conditional Custom Editor with Popup 1 Answer

How do i bring back the GUI option in the scene view 0 Answers

4.6 - Sceneview GUI.Button not working correctly 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges