• 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 Jake-L · Feb 13, 2011 at 04:17 PM · editormeshmeshfilterexecuteineditmode

How to prevent editor to set the scene dirty if a script changes a mesh (@ExecuteInEditMode)

I've got a script that manages a custom mesh and needs to run in the editor. It works like intended, but changing the mesh (say by calling "GetComponent().sharedMesh.Clear()") causes the scene to set it's state to dirty (the * in the editor's titlebar shows up permanently and indicates a changed scene).

As I generate the mesh by code there's no reason for the user to save those changes, so is there a way to disable t$$anonymous$$s behavior?

T$$anonymous$$s must be possible somehow as the buildin ParticleSystem both runs in the editor and changes it's mesh without setting the scene dirty.

Update: I tried HideFlags.DontSave but without luck. As soon as I change some vertices the scene went dirty.

Update 2: Like tranquility suggested, I've tried the following:

[ExecuteInEditMode] public class Meshtest : MonoBehaviour { Mesh mMesh;

 void OnEnable () {
     mMesh = new Mesh(); // create a private mesh
 }

 void Update()
 {
         mMesh.Clear(); // scene will turn to dirty state
 }

}

but even without any MeshFilter and MeshRenderer present in the scene it will turn to changed state immediately.

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
3
Best Answer

Answer by Quazistax · May 05, 2011 at 08:13 AM

Changes to "sharedMesh" are persistent, for example, if you change it in play mode, changes will be kept after exiting play mode, scene will be changed. If you change MeshFilter's "mesh" property, changes will disappear after exiting play mode. Unfortunately, seems like you can not change "mesh" property in edit mode.

What you could do is creating one or more Mesh you want to show and use Grap$$anonymous$$cs.DrawMesh. If you want to keep "sharedMesh" intact as part of your game object, but want to $$anonymous$$de it, disable MeshRenderer component.


EDIT: I set $$anonymous$$deFlags and it worked - private mesh changes don't make scene dirty.

void OnEnable () 
    {
        mMesh = new Mesh(); // create a private mesh
        mMesh.$$anonymous$$deFlags = HideFlags.HideAndDontSave;
    }

You will get t$$anonymous$$s message, probably when saving scene: "Cleaning up leaked objects in scene since no game object, component or manager is referencing them. Mesh has been leaked # times." But it is harmless.

However, if you find a way to avoid that message, it would be nice to know how.


EDIT: Move the initialization code from OnEnable to Awake function, I don't get "leaked objects" message after that.

Comment
Add comment · Show 11 · 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 Jake-L · May 06, 2011 at 11:03 AM 0
Share
avatar image Quazistax · May 06, 2011 at 10:41 PM 0
Share
avatar image Jake-L · May 07, 2011 at 07:39 AM 0
Share
avatar image Quazistax · May 07, 2011 at 08:45 AM 0
Share
avatar image Quazistax · May 07, 2011 at 08:56 AM 0
Share
Show more comments

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Weird issue with mesh.Clear() 1 Answer

How do I access Mesh/ Meshfilter in Editor code? 3 Answers

Is there any way to reset the default meshes? 3 Answers

Mesh memory leak error 0 Answers

How can I modify the mesh in OnPostprocessModel? 2 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