Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
3
Question by Michael Stevenson · Mar 20, 2011 at 01:39 AM · guiinspectorcustom-inspector

Detecting GUI.changed using DrawDefaultInspector

I've created a custom editor that displays the default inspector. I'd like to detect when inspector values have changed, but GUI.changed always returns false.

Does GUI.changed work with DrawDefaultInspector? If not, is there an alternative solution?

[CustomEditor(typeof(PlayerWalk))] public class PlayerWalkEditor : Editor { public override void OnInspectorGUI () { PlayerWalk t = (PlayerWalk)target;

     DrawDefaultInspector ();

     Debug.Log (GUI.changed);
 }

}

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

3 Replies

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

Answer by Byterunner · Apr 04, 2011 at 03:58 PM

Yes, it does, but GUI.changed is set to true only for the frame that the GUI changes. The following will print to the console whenever it detects a change in your script:

I don't know what your PlayerWalk script is doing, so I made a quick one of my own:

using UnityEngine;

public class PlayerWalk : MonoBehaviour { public float speed = 1.0f;

 void Start()
 {

 }

}

And here is the full PlayerWalkEditor.cs:

using UnityEngine; using UnityEditor;

[CustomEditor(typeof(PlayerWalk))]

public class PlayerWalkEditor : Editor { public override void OnInspectorGUI () { PlayerWalk t = (PlayerWalk)target;

     DrawDefaultInspector ();

     if(GUI.changed)
     {
         Debug.Log ("changed");
     }

 }

}

Make sure you put PlayerWalkEditor.cs into a folder called 'Editor'. Now when you add the PlayerWalk script to an object and change the speed variable, "changed" is printed to the console.

Comment
Add comment · Show 7 · 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 Michael Stevenson · Apr 05, 2011 at 07:52 PM 0
Share

Debug.Log("changed") is never called, so I'm certain that GUI.changed is never beco$$anonymous$$g true. It sounds like this may be a Unity bug.

avatar image Byterunner · Apr 05, 2011 at 09:37 PM 0
Share

It's not a bug, it's working correctly. I've updated my answer to provide more insight.

avatar image Michael Stevenson · Apr 07, 2011 at 04:38 PM 0
Share

Thanks, but I'm afraid I should have clarified in my original post. GUI.changed had been working before I began using DrawDefaultInspector(), and indeed continues to work in a few other editors within the same project which implement their own custom inspector GUI. I recently replaced all of PlayerWalkEditor's GUIlayout methods with a single DrawDefaultInspector call which immediately broke the if(GUI.changed) code block.

avatar image Michael Stevenson · Apr 07, 2011 at 05:06 PM 0
Share

In addition, OnInspectorGUI is called successfully, but the Debug.Log(GUI.changed) line in my original post will always log "false" when a default GUI control for one of PlayerWalk's public fields is manipulated within the inspector.

avatar image Byterunner · Apr 07, 2011 at 05:32 PM 0
Share

If you're not putting your Debug.Log(GUI.Changed) command within some kind of if() block, it's just going to print "false" every single frame. I had originally took your posted code and found that it did print "true" for the one frame that it detected the GUI change, but then immediately went back to "false" on the very next frame. I had to scroll way back in the console to find the true, but it was there. GUI.changed does not persist from frame to frame; it's always false unless you're in the middle of changing something. If you want the value to persist, you'll need to make a new variable.

Show more comments
avatar image
4

Answer by ciela_spike · Sep 17, 2014 at 11:19 AM

Just use the return value of DrawDefaultInspector, like:

 if (DrawDefaultInspector()) {
     Debug.Log("Changed");
 }
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
avatar image
0

Answer by adamonline45 · Feb 07, 2012 at 06:13 AM

This seems to be about a year old, but I've observed that using the code above, it only says 'changed' when I change the last inspector-visible property. I suspect that if you want all the inspector values to emit this 'changed' text, you would need to override the InspectorGUI implementation for each property, with the check for GUI.Changed() after each. At least, that's my speculation at this point.

I'm still researching this, and will update if appropriate.

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

2 People are following this question.

avatar image avatar image

Related Questions

How to show an array of custom objects in Inspector? 2 Answers

How to create a unique looking inspector, 1 Answer

Prefix label greyed out when following component disabled 1 Answer

How to view variables from a script stored inside another script in Inspector 1 Answer

Questions Regarding Images in Custom Inspector/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