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
0
Question by DerKleineTomy · Jan 28, 2013 at 11:43 AM · inspectorreset

Problem with Reset and Custom Inspector

I have a MonoBehaviour which contains an array but I didn't like the way the array elements are shown. So I created a custom inspector which does the job, but now the inspector does not update when I reset the MonoBehaviour(right-click->Reset). Everything works fine except for the Reset. When I reset, the values don't get updated until I hit the play button. I tried to use SetDirty in OnInspectorGUI and also SetDirty in the MonoBehaviours Reset method but nothing seems to work.

Without the custom inspector, the reset works just fine.

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

2 Replies

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

Answer by DerKleineTomy · Jan 29, 2013 at 05:29 PM

I solved the problem. After I modify my MonoBehaviour, I have to call serializedObject.ApplyModifiedProperties() and serializedObject.Update(). I did it once when trying to solve the problem but I didn't notice a reset because the inspector updates when I leave the modified property. For example I set a value to 1000 and then do the reset, the value won't be updated to the default until I click on another field.

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 CodeMasterMike · Jan 28, 2013 at 01:03 PM

To reset your values in the inspector, you need to add the reset function to your script.

 function Reset()
 {
    // Set your data to a default value/s here.
 }

You can read more in the reset documentation.

Comment
Add comment · Show 3 · 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 DerKleineTomy · Jan 28, 2013 at 07:02 PM 0
Share

That's what I'm doing. It works as long as I don't use a custom inspector. The reset method gets executed but the custom inspector does not show the new values until I hit the play button (refreshes the inspector I think). I already tried to add SetDirty(this) at the end of the reset method but it doesn't work. SetDirty and Update in OnInspectorGUI didn't work either.

In short: Reset works with default inspector, reset doesn't work with custom inspector.

avatar image CodeMasterMike · Jan 29, 2013 at 05:49 AM 0
Share

$$anonymous$$aybe you can post some of the code you have, so that people here might find what is causing this behavior?

avatar image DerKleineTomy · Jan 29, 2013 at 04:20 PM 0
Share

I solved the problem. After I modify my $$anonymous$$onoBehaviour, I have to call serializedObject.Apply$$anonymous$$odifiedProperties() and serializedObject.Update(). I did it once when trying to solve the problem but I didn't notice a reset because the inspector updates when I leave the modified property. For example I set a value to 1000 and then do the reset, the value won't be updated to the default until I click on another field.

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

10 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

Related Questions

how to reset only specific properties? 2 Answers

Inspector not refreshing 1 Answer

How to keep certain values on MonoBehaviour Reset method. 1 Answer

My inspector icons keep resetting, can anyone help? 0 Answers

Inspector value resets on prefabs 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