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 ChaoticBoredom · Oct 06, 2012 at 10:01 AM · editorsavingcustom editor

Custom Editor Script Sets Scene as Dirty Regardless of Changes

So, our team has made a couple of custom editor scripts to try and make some of our tools more usable. They work for the most part, but we've found an interesting side-effect. As soon as there's a custom script for any object, the unity scene gets set to 'dirty', even when no changes have been made. The only way to avoid getting the save notification is to not click in the scene editor at all, and sometimes that doesn't even work.

The Undo dialog given is 'Change Selection', but with objects not using custom editors, this does not flag the scene as dirty. Is there a way to fix this behaviour? It's not necessarily breaking any scenes, but it's very irritating to get the save dialogue constantly.

I've included the simplest/shortest version of our editor scripts below.

 #pragma strict
 
 @CustomEditor (ConveyorController)
 class ConveyorControllerEditor extends Editor {
 
     function OnSceneGUI() {
         Undo.SetSnapshotTarget(target, "Altered Conveyor");
         var script:ConveyorController = target as ConveyorController;
 
         var pointA:Vector3 = script.GetPointA();
         var pointB:Vector3 = script.GetPointB();
         script.transform.position = (pointA + pointB) / 2;
 
         var A:Vector3 = Handles.PositionHandle(pointA, Quaternion.identity);
         var B:Vector3 = Handles.PositionHandle(pointB, Quaternion.identity);
 
         var swap:float = 0;
 
         //A is always left of B (smaller val)
         if(A.x > B.x)
             A.x = B.x;
 
         if (GUI.changed) {
             EditorUtility.SetDirty(target);
 
             script.SetPointA(A);
             script.SetPointB(B);
         }
 
         if(Input.GetMouseButtonDown(0)) {
             Undo.CreateSnapshot();
             Undo.RegisterSnapshot();
         }
     }
 }
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 ChaoticBoredom · Oct 22, 2012 at 02:40 AM 0
Share

Even knowing if this is default behaviour for custom editors in Unity would be nice, so I don't waste any more time trying to fix this.

1 Reply

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

Answer by ChaoticBoredom · Jan 15, 2013 at 07:41 PM

Solved this. The problem w/ this script in particular was line 12

    script.transform.position = (pointA + pointB) /2;

Since OnSceneGUI is being called constantly, the object was constantly moving, even if it wasn't visible. This was the cause of the problems for many of the similar scripts we had. A simple if check usually solved the problem, since we only want code of this nature to be executed when necessary anyway. In this case, the offending line was moved down in the if (GUI.changed) block.

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

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How could I merge 2 components' inspectors through a custom editor? 2 Answers

UnityEventBase editor changed callback 0 Answers

List of CustomEditor inside CustomEditor 1 Answer

Binary Serialization (In Editor) - Path Access denied / File not found 0 Answers

Field Attribute to auto insert in custom inspector 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