Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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 /
This question was closed Mar 21 at 08:18 PM by andrew-lukasik for the following reason:

The question is answered & thread keeps being targeted by spammers

avatar image
1
Question by liortal · Sep 01, 2014 at 04:02 PM · c#editorobjecteditor-scripting

Unity API for checking if an object was modified

Is there any API that Unity provides for determining whether an object was edited (e.g: some value changed in its inspector) ?

There is a method called EditorUtility.SetDirty that accepts an Object and sets it as dirty.

Is there a method for determining if a given object is currently dirty?

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

  • Sort: 
avatar image
3
Best Answer

Answer by vexe · Sep 01, 2014 at 04:09 PM

If you want this at edit-time and you like hacks, this looks like it should work (not tested)

 bool isDirty = (bool) typeof(Editor).GetProperty("isInspectorDirty", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(myEditor, null);

alt text


dirty.png (7.6 kB)
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 liortal · Sep 01, 2014 at 04:50 PM 0
Share

Actually, i am not sure this will not work, but it's close. This checks for the Editor class, whether the inspector is dirty. Usually, you create classes derived from Editor for different asset types. You would then have to get the currently active editor object, and then check for it whether it's dirty or not. This seems to be what the ActiveEditorTracker class offers (http://docs-jp.unity3d.com/Documentation/ScriptReference/ActiveEditorTracker.html). I will give that a check.

avatar image vexe · Sep 01, 2014 at 04:53 PM 0
Share

This will check if the editor/inspector for a certain object is dirty or not (thus the object is modified or not) - What is your actual use-case I might help you better given more detail

avatar image guavaman · May 18, 2016 at 07:13 PM 0
Share

This only seems to work very intermittently. In testing within OnInspectorGUI and checking for the isInspectorDirty state on the target Editor, most frames return false. Occasionally a frame will return true for isInspectorDirty, specifically when the object is first selected, but the vast majority of updates return false after the initial selection.

avatar image
2

Answer by BMayne · Sep 01, 2014 at 04:07 PM

Hey There,

You can use OnValidate(). That functions gets called whenever something changes in the inspector.

This will not tell you if something changed in the scene. You can hook into the AssetModificationProcessor to see when something is going to be saved if it was dirty.

I am not sure if there is a direct way to check if an Object is dirty.

Regards,

Comment
Add comment · Show 2 · 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 · Sep 01, 2014 at 04:16 PM 0
Share

Thanks. I know Asset$$anonymous$$odificationProcessor, but that would only work for assets that are being saved. Any modification that is done inside the editor is not immediately saved to disk. OnValidate is nice but i want to listen to ANY object that is being modified, not specifically to ones that i have control over.

avatar image BMayne · Sep 01, 2014 at 04:19 PM 0
Share

You will have to break into using Reflection like vexe said then.

avatar image
0

Answer by JasonC_ · Mar 21 at 01:52 AM

 EditorUtility.IsDirty

https://docs.unity3d.com/ScriptReference/EditorUtility.IsDirty.html

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

Follow this Question

Answers Answers and Comments

27 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

Related Questions

Updating object on inspector value changes in editor 1 Answer

Saving class fields in the Asset 0 Answers

Trouble grabbing and holding a cube. 0 Answers

Gizmos icons 0 Answers

Why does Assembly-CSharp reference UnityEditor.dll 0 Answers


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