Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 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
1
Question by liortal · Aug 13, 2014 at 12:47 PM · c#editoreditor-scriptingexecuteineditmode

Updating object on inspector value changes in editor

I have a game object that displays text information (some number). The number is controlled from a script that is attached to that game object.

I'd like the changes to reflect in the editor as i change this number.

So far, i got away using this:

 private void OnValidate()
 {
     UpdateText();
 }

Whenever i change a value, the change will be reflected immediately.

There are 2 issues with this approach:

  1. The OnValidate callback should be used for validating data. This is kind of a hack to use that for updating other things.

  2. Whenever i load the game object (e.g: from scripting) and not by dragging it into the scene, it will not update its text using OnValidate (since no "change" was done to the data)

Is there any better way to achieve this? I know about [ExecuteInEditMode], but this is "dirty" - forcing me to add another component to my game object, one that i don't need when releasing the game.

Comment
Add comment · Show 1
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 Nims · Aug 13, 2014 at 01:22 PM 0
Share

Haven't really understood the scenario your describing. You want changes made in the editor to be reflected by the text(attached to the game object) which is in the scene, while in edit mode? Are you creating the game object in the scene while your in edit mode? As you don't want to use [ExecuteInEdit$$anonymous$$ode] the only suggestion I can give is you need to poll the data somehow? You might wanna try and see if EditorApplication.update can be of any help. (Aroyo Nimrod)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by smoggach · Aug 13, 2014 at 01:54 PM

Perhaps there's a way to get what you want by implementing the getter/setter of your property.

In any case you must have some sort of way to change the value during runtime so the key will be to do it in the same manner in the editor.

You can also try making a CustomPropertyDrawer for that property. The code will only be compiled into the editor and you can use it to update your text when IT is invalidated.

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 liortal · Aug 13, 2014 at 02:09 PM 0
Share

What is the difference between a CustomPropertyDrawer and a CustomEditor ?

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

23 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

Related Questions

Unity API for checking if an object was modified 3 Answers

Trouble setting the object reference in a property drawer 0 Answers

How can an editor script know when another script was removed from the project? 1 Answer

Is there a way to show and editor windows, within another editor window? 0 Answers

Custom Editor Script resets values on Play 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