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 lightprogramming · Jun 22, 2014 at 06:42 PM · meshresetmeshfiltermodify

Modify Mesh and reset back to original at end of application

Im trying to modify the current mesh at run time and reset everything back to the way it was at the end of the application.

For some reason OnApplicationQuit runs as expected, once at the end of the application. But the mesh is not set back to the shared mesh. I know this because in the editor it stays the same, the copy i made is in the editor MeshFilter slot.

Ex: The MeshFilters mesh name is "Sphere", when this script runs it is replaced with "Sphere_temp", and when the application ends it should return back to "Sphere".

 void Start () 
 {
 
     //get reference of sharedmesh
     this.sharedMeshOriginal = GetComponent<MeshFilter>().sharedMesh;
 
         //copy shared mesh
     this.meshCurrent = new Mesh();
     this.meshCurrent.name = this.sharedMeshOriginal.name + "_temp";
     this.meshCurrent.vertices = this.sharedMeshOriginal.vertices;
     this.meshCurrent.triangles = this.sharedMeshOriginal.triangles;
     this.meshCurrent.uv = this.sharedMeshOriginal.uv;
     this.meshCurrent.normals = this.sharedMeshOriginal.normals;
     this.meshCurrent.colors = this.sharedMeshOriginal.colors;
     this.meshCurrent.tangents = this.sharedMeshOriginal.tangents;
 
         //set current mesh to new mesh
     GetComponent<MeshFilter> ().mesh = this.meshCurrent;
 
 }
 
 void OnApplicationQuit ()
 {
 
         // set mesh back to original shared mesh
     if (this.sharedMeshOriginal != null) 
           this.GetComponent<MeshFilter> ().mesh = this.sharedMeshOriginal; // NOT WORKING!!!!!
 }
 
 void Update()
 {
 
         //modify current mesh
 }


Note: this.GetComponent ().mesh = this.sharedMeshOriginal; works fine if it runs in the update loop for somereason. The mesh is set back to the original with noproblem, but when it runs in OnApplicationQuit , it fails.

Comment
Add comment · Show 2
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 robertbu · Jun 22, 2014 at 06:50 PM 0
Share

I don't see your problem, but you are going the long way around. Just use Instantiate() for making the copy of your mesh.

avatar image lightprogramming · Jun 22, 2014 at 08:11 PM 0
Share

thanks for the installation() tip. But the problem still remains. When the application ends there is a "Sphere(Clone)" in the $$anonymous$$eshFilter.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Dreamora · Jun 22, 2014 at 10:23 PM

You are by error writing into .mesh instead of .sharedMesh. Writing into .mesh will always create a clone as you are trying to modify the mesh of just this instance which is not able to point to a 'global' mesh.

For the 'change during runtime', this is actually what you want to do, but in OnApplicationQuit you would want to use sharedMesh Unless something went wrong, Unity should have printed a warning to the Console too, informing you that the .mesh writing there is leaky, causing memory waste in your scene when done within the editor.

If you would want to alter just 1 mesh in the editor in a persistant way btw, you would want to instantiate the previous mesh and assign it to sharedMesh instead (or create a mesh and store it as a new asset through AssetDatabase)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

change a image into a mesh 2 Answers

Is it possible to make vertices defined by a mesh and mesh filters animating? 0 Answers

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

Generate a highpoly sphere with mesh collider procedurally 2 Answers

Getting Bounding box from a collider with children 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