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 /
  • Help Room /
avatar image
0
Question by DorianF · Oct 19, 2016 at 10:10 AM · unityeditorinspector5.3refresh

Changes in Custom Inspector not reflected in Scene

Hi,

I'm experimenting a bit with custom editor, and so far, everything is almost fine.

The "almost" part is some problem with my latest script, a component supposed to update a couple GUIText (in other GameObjects), in fact, I want this script to be a centralized way of editing several texts at a time.

The thing is that whenever I update the string field of my CustomEditor, it does update the string field of the GUIText, but the text itself, as I see it in my scene, doesn't get refreshed. To be fair, sometimes it does refresh the GUIText... But in a messed up way... It will refresh afterward, whenever I move the GUIText, or enable/disable it, but it's kinda... Messy, and I wish I could solve this issue.

I guess it might be a bit hard to explain / understand, but images are worth a thousand words, so here it is :

Image Sometimes, instead of a messed up text, it just doesn't update at all.

Notes :

  • I do call Undo.RecordObject to save my object

  • I don't call EditorUtility.SetDirty, it apparently shouldn't be used anymore (since Unity 5.3, I'm using 5.3.6p5 by the way), and although it does update the scene view / game view properly, it doesn't save my serialized attributes properly (they are reseted when I reload the scene / reopen the project)

  • Although I don't think it's related to the issue, the string exposed in the editor is actually part of a non-serialized Dictionary. The key / value are serialized by being stored in 2 Lists, "key" and "value" as suggested by this page of the documentation : https://docs.unity3d.com/ScriptReference/ISerializationCallbackReceiver.OnBeforeSerialize.html

  • If I add "base.InspectorGUI()" at the beginning of my custom InspectorGUI code, those lists become available in the editor (instead of the Dictionary values, wich I do not want). Updating the "value" list does what I want, meaning that the original InspectorGUI has lines of code doing what I want to, I just need to figure wich lines... But I can't see the code of the original Editor class, can I?

So, basically, what I need is probably some generic (not GUIText related) line of code that updates the scene I guess.

This is a simplified version of my code :

         serializedObject.Update();
         MyCustomComponent myScript = target as MyCustomComponent;

         SerializedProperty toa = serializedObject.FindProperty("textObjectArray");

         EditorGUI.BeginChangeCheck();
         EditorGUILayout.PropertyField(toa, true);
         EditorGUILayout.Space();

         EditorGUILayout.LabelField("ROTATION Instruction Text");
         //Saves the value to a serialized attribute of MyCustomComponent and changes the text attribute of all Texts stored within the textobjectArray
         myScript.setInstructionText(EditorGUILayout.TextArea(myScript.getInstructionText, GUILayout.MaxHeight(30)));

         if (EditorGUI.EndChangeCheck())
         {
             serializedObject.ApplyModifiedProperties();
         }

         if (GUI.changed)
         {
             Undo.RecordObject(myScript, "Saving Instruction Dispatcher of "+ myScript.gameObject.name);
         }

I believe I'm missing an instruction to refresh the scene based on the changes I've made. If anyone has a clue on what I'm missing, I'd follow any lead, thanks :)

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 DorianF · Oct 19, 2016 at 12:30 PM

Ok, I guess I found what I was missing, or at least a part of it, though I feel like my answer will be incomplete.

I finally found something alike my problem here http://answers.unity3d.com/questions/1042052/change-text-in-text-component-from-editor-script.html so I just update my code :

 if (GUI.changed)
 {
         //NEW
         foreach(Text text in myScript.textObjectArray)
         {
             EditorUtility.SetDirty(text);
         }
         //END NEW
         Undo.RecordObject(myScript, "Saving Instruction Dispatcher of "+ myScript.gameObject.name);
  }

What I was doing before was setting "myScript" itself as dirty, wich was somehow refreshing the view with my latest changes, but not saving them within my script.

I'm not exactly sure as to why this works better than what I was doing before, but it does. However, when I read the docs on SetDirty I understand it as "One should probably not use SetDirty anymore, or at least, not in 95% of the cases." and I don't feel like I'm in the remaining 5% cases, so I just feel like there should be a better solution...

For now, I'll just use this one

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 Quatum1000 · Jan 01, 2018 at 01:23 PM 0
Share

Add 1 point for you! Thanks this works well for me 2017.1.b10. This issue is fixed since years in 2017.3.

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

79 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

Related Questions

Unity not Version Controlling Inspector Settings for GameObjects 1 Answer

Why in Unity 5.3 after I edit script in mono and return to the editor it shows importing script window? 0 Answers

Drop down menu for public variables on a component in the inspector. 0 Answers

Variables In Editor Inspector Strings 1 Answer

LINEAR COLOR SPACE CAUSE ICONS TO BECOME DARKER NOT SOLVED 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