Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by NGC6543 · Dec 08, 2015 at 11:56 AM · editor-scriptingbooleanonsceneguioninspectorgui

( Schrödinger's boolean?) custom Editor class OnSceneGUI() and OnInspectorGUI() accessing variable problem!!

Hi, I made a custom editor and it behaves weird.

I created something like this :

 [CustomEditor(typeof(MyCustomClass))]
 public class MyCustomClassEditor : Editor{
     bool myBool = false;
     
     void OnInspectorGUI(){
         DrawDefaultInspector();
         if(myBool){
             if(GUILayout.Button("Disable")){
                 myBool = false;
                 //DO SOMETHING
             }
         }else{
             if(GUILayout.Button("Enable")){
                 myBool = true;
                 //DO SOMETHING
             }
         }
     }
     
     void OnSceneGUI(){
         if(myBool){
             //DRAW SOMETHING ON THE SCENE WINDOW
         }
     }
 }


this creates a button in the inspector that toggles the boolean myBool. And it affects the way the OnSceneGUI() behaves.

In fact, it worked without any trouble yesterday, but when I come back for work, it does not work anymore. I tried to figure out what causes the problem, I added a debug script

Debug.Log("Inspector myBool : "+myBool); => OnInspectorGUI() Debug.Log("Scene myBool : " +myBool); => OnSceneGUI()

and here is what I have found :

From OnInspectorGUI() the value changes with respect to the button click. But OnSceneGUI() the value is fixed to false. Even if the value from the OnInspectorGUI() is true, OnScenGUI() shows false. and those value exist simultaneously.

What the... is this a Schrödinger's boolean???

Comment
Add comment · Show 5
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 Greg-Bassett · Jan 12, 2016 at 03:38 PM 0
Share

I am having exact same problem, did you figure out a solution?

avatar image NGC6543 Greg-Bassett · Jan 13, 2016 at 01:11 AM 0
Share

Unfortunately, no. I didn't find the solution..

avatar image NGC6543 Greg-Bassett · Jan 13, 2016 at 02:10 AM 0
Share

OG23 shared a solution with us.

avatar image hulahoolgames · Jan 12, 2016 at 04:00 PM 0
Share

Does it work if you make the bool public?

avatar image Greg-Bassett · Jan 13, 2016 at 10:32 AM 0
Share

Declaring as Public makes no difference, in fact I am using a string in my code and setting the string in OnSceneGUI to a value does nothing, I have a Debug.Log in OnInspectorGUI and it puts Null in the console?

1 Reply

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

Answer by hulahoolgames · Jan 13, 2016 at 01:59 AM

So what I found was, it does not print any statements in the OnSceneGUI until I move my mouse over to the scene view. Once I do that it starts printing the log I have. Then I added a call to SceneView.RepaintAll() and then the log statement inside OnSceneGUI was printed as soon as I clicked the Enable button. Hope this helps!

 [CustomEditor(typeof(MyCustomClass))]
 public class MyCustomClassEditor : Editor {
 
     bool myBool = false;
 
     public override void OnInspectorGUI() {
         DrawDefaultInspector();
 
         if(myBool){
             if(GUILayout.Button("Disable")){
                 myBool = false;
                 Logger.Log("Disabled. Bool set to false");
             }
         }else{
             if(GUILayout.Button("Enable")){
                 myBool = true;
                 Logger.Log("Enabled. Bool set to true");
                 SceneView.RepaintAll();
             }
         }
     }
 
     void OnSceneGUI(){
         if(myBool){
             Logger.Log("ONSCENEGUI : Bool is true");
         }
     }
 }

Comment
Add comment · Show 2 · 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
avatar image NGC6543 · Jan 13, 2016 at 02:07 AM 0
Share

Oh, I did move my mouse over the scene view to refresh the view, I didn't know the method SceneView.RepaintAll(). Thank you for your answer!

avatar image hulahoolgames NGC6543 · Jan 13, 2016 at 02:11 AM 0
Share

No problem! Glad it helped :)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Editor values not updating in OnSceneGUI 1 Answer

Is there a way to draw on the scene view from an asset being inspected by the Inspector? 0 Answers

Why does the SceneView camera return jittery values? 0 Answers

There is a way to check if a handle is highlighted? 1 Answer

Support multiple selection with OnSceneGUI handles (The targets array should not be used inside OnSceneGUI) 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