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 wachowski1 · Jul 26, 2016 at 07:35 AM · guieditoreditor-scriptingeditor extension

Editor Control Automagically "Filling" in Data

Hi,

I'm building an editor extension that includes inspecting and modifying the fields/properties of ScriptableObjects, almost exactly like Unity's inspector window. I have an issue when I switch inspector targets and it's wracking my brain trying to fix it. Clicking in the editor view causes a node (or no node) to be selected, which also executes an inspector window callback. The inspector window receives a reference to the selected object in this callback and

  • Destroys the old inspector (which itself is a ScriptableObject)

  • Determines the appropriate inspector to display (user-scripted, auto-generated, or none)

  • Creates an instance of the applicable inspector type and assigns it to the window

  • Repaints at the end of the execution path

The inspector window's OnGUI function calls the inspector's OnInspectorGUI behavior (if it exists) and repaints.

The issue arises when I edit the value in a control backed by one ScriptableObject's field, switch to a different ScriptableObject without moving keyboard focus away from that control, and then resume focusing the "equivalent" control on the new ScriptableObject. I've included a video demonstrating what happens: http://webmshare.com/6wOGj

This is what information I've collected about the unintended behavior:

  • It does not affect the SerializedObject backing the inspector until I begin editing the field. You can see this in the video. When I start typing the name of the node in the editor takes the value of the control.

  • It affects all of my inspectors and every control type. The video features an auto-generated inspector, but I knew about this issue from early testing with custom inspectors. So long as I modify controls shared by two nodes, it happens.

  • I think has to do with keyboard focus. If I do anything that removes keyboard focus from the control, the next inspector doesn't receive the ghost value. This isn't fixed by setting GUIUtility.keyboardControl to 0 in the callback or in OnLostFocus, though.

  • The control IDs of two "equivalent" controls are the same. In my example, both name text fields are ID 239.

  • GUI.changed is not true when the ghost value appears, so it is merely cosmetic.

I feel like the solution to my issue is either so simple that I am overlooking it, or something internal that I'm missing. Hoping for the former.

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
Best Answer

Answer by Bunny83 · Jul 26, 2016 at 08:41 PM

Well, setting the keyboardControl to "0" should work as the editor would then reinitiate it's text based on the passed text. You can try to also set EditorGUIUtility.editingTextField to false. This will directly set a value inside the recycled text editor that Unity uses internally.

The textfield actually has this code:

 if (editor.controlID == id && GUIUtility.keyboardControl != id)
 {
     editor.controlID = 0;
 }

As as soon as the text field is called while keyboardControl is not the id of this control it would reset the editor controlID. Are you sure that your GUI receives the layout event?

It seems your system is quite complex. What isn't really clear is do you actually use Unity's Inpectorwindow or do you have created your own EditorWindow for that?

Comment
Add comment · Show 1 · 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 wachowski1 · Jul 26, 2016 at 09:01 PM 0
Share

This helped!

The inspector window, which is my own EditorWindow and not Unity's, is now using

 void OnLostFocus() {
     ...
     EditorGUIUtility.editingTextField = false;
     ...
 }

which eli$$anonymous$$ated the documented side effect. The window is receiving all events, including layout. Thank you!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

ShaderGraph-like EditorWindow 0 Answers

How to get unity3d editor account id or unique id 0 Answers

Queue method to be called after asset processor is done 0 Answers

Trigger an event from editor script? 0 Answers

How can i create a pup-up menu like the one for choose the shader on materials in unity 2019? 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