Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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 paladinrose · Dec 11, 2016 at 08:11 AM · editor-scriptingonsceneguioninspectorgui

Editor values not updating in OnSceneGUI

So, here's my basic problem. My custom editor is using both OnInspectorGUI and OnSceneGUI.

The editor itself has several values - mostly integers - for holding editor state information. Things like which tab is selected, or which options in a list, things like that. When those values are updated, OnSceneGUI reports no change in them. Here is a simplified version:

 public class ProblemFinder : MonoBehaviour {
 
     // Tried containing variables on editor target, instead of editor, but got the same result.
     // public int testInt = -1;
     // public string[] testButtons = new string[] { "Test 1", "Bob", "Blueberry" };
 }
 
 
 [CustomEditor (typeof(ProblemFinder))]
 public class ProblemFinderEditor : Editor {
 
     int testInt = -1, currentInt = -1;
     string[] testButtons = new string[] { "Test 1", "Bob", "Blueberry" };
 
     public override void OnInspectorGUI()
     {
         Debug.Log("Test Int Value: " + testInt.ToString());
         for (int i = 0; i < testButtons.Length; i++)
         {
             
             if (currentInt != i && GUILayout.Button(testButtons[i]))
             {
                 testInt = i;
                 Debug.Log("Clicked " + testInt.ToString() + ". " + testButtons[i]);
                 SceneView.RepaintAll();
             }
             else if(currentInt ==i)
             {
                 GUILayout.Label(testButtons[i]);
             }
         }
     }
 
     public void OnSceneGUI()
     {
         Debug.Log("Scene View Updated: " + testInt.ToString());
         if (testInt != -1)
         {
             // I never see this message.  testInt ALWAYS == -1 in this function
             Debug.Log("Test Int = " + testInt.ToString());
             currentInt = testInt;
             testInt = -1;
         }
     }
 }

I see the three buttons I would expect, in the Inspector: Test 1, Bob, and Blueberry.

Clicking Blueberry returns the following:

Clicked 2. Blueberry

Scene View Updated: -1

My initial debug comment, in OnInspectorGUI confirms that testInt HOLDS its value of 2.

Even so, OnSceneGUI ALWAYS returns it with a value of -1. Anyone have any idea why?

I'm using Unity 5.5. I was not having this problem prior to updating, and some, but not all, other teammates, also now updated to 5.5 are NOT having the same issues.

I have tried reimporting the scripts, I've tried creating the test scripts above (which DO exhibit the exact issues I describe here), I've tried reinstalling Unity - and none of that has made an impact so far.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Dec 11, 2016 at 11:54 AM

Well, i don't have the latest Unity version but i would simply guess that Unity creates a seperate editor instance for the sceneview callback. An Editor is not ment to hold data as it's just an editor for the inspected class.

Try printing the instance ID of each editor instance.

 Debug.Log("OnInspectorGUI: " + GetInstanceID());
 
 Debug.Log("OnSceneGUI: " + GetInstanceID());

Most likely they are not the same. They might have completely seperated the drawing of the scene view from the drawing of the inspector.

One solution could be to use static variables inside your editor. Or store the things you need in both editor instances in your actual MonoBehaviour. If it's more like a global editor setting you could also use EditorPrefs.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

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

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

Add trasform to list using editor gui. 1 Answer

Using handles to edit custom classes 2 Answers

How do you instantiate a reference in a custom editor? 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