• 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 steinbitglis · Jan 02, 2012 at 02:52 PM · meshfilter

Why does MeshFilter.sharedMesh change when I change MeshFilter.mesh?

Hi! I'm trying to create a mesh without changing the original. I thought that I could use Meshfilter.sharedMesh to access the original mesh, but it seems as if it too gets changed.

This is my script... the result a mesh that keeps changing for every update. What I thought would happen was that I got the same mesh every frame.

 def Update():
     m = Matrix4x4.identity
     m.SetRow(1, Vector4(.1f, 1f, 0f, 0f))

     filter = GetComponent of MeshFilter()
     vertices as (Vector3) = array(filter.sharedMesh.vertices)
     for vertice in vertices:
         vertice = m.MultiplyPoint(vertice)
     filter.mesh.vertices = vertices
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 steinbitglis · Feb 14, 2012 at 08:13 PM

We took Dreamora's advice, and kept the vertices completely separate.

 import UnityEngine
 
 class MyMesh (MonoBehaviour):
 
     public baseTransformation = def(time as single):
         m = Matrix4x4.identity
         m.SetRow(0, Vector4(1f, Mathf.Sin(time), 0f, 0f))
         return m
 
     private projectionStart as single
     private originalVertices as (Vector3)
 
     def Start():
         projectionStart = Time.time
         originalVertices = (Vector3(-0.5f, 0f, 0f), Vector3(0.5f, 0f, 0f), Vector3(-0.5f, -1f, 0f), Vector3(0.5f, -1f, 0f))
 
     def Update():
         m = baseTransformation(Time.time - projectionStart)
 
         copiedVertices = array(originalVertices)
 
         p = 0
         while p < originalVertices.Length:
             copiedVertices[p] = m.MultiplyPoint(originalVertices[p])
             p += 1
 
         filter.mesh.vertices = copiedVertices
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
2

Answer by Dreamora · Jan 03, 2012 at 11:18 PM

The sharedMesh of a MeshFilter is always what you find on mesh too. By accessing it in sharedMesh you simply prevent it from dublicating an own instance of it if you change it while changing .mesh will generate an own dublicate just for this mesh filter.

and I don't see why you should get the same mesh every update. You are not multiplying the vertex with identity, you are actively transforming it as such you get a new mesh every frame.

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 steinbitglis · Jan 04, 2012 at 11:32 AM 0
Share

Yes, but I expect the same new mesh every frame. Now it keeps the changes from each step to the next.

avatar image Dreamora · Jan 04, 2012 at 03:27 PM 2
Share

If you want the same mesh every frame you either must use a matrix m thats the identity or you must not use the meshes vertices cause you apply a transformation to the newly generated mesh every frame. Don't forget that when you change filter.mesh, its shared mesh is now this mesh as well (as it no longer shares meshes with some other filter as you replaced it locally)

For what you want to achieve with 'always the same mesh' you would need to store either the original vertices or the original mesh in some reference that you do not change and then execute your code on top of that mesh / vertices, not on top of the mesh thats being used and updated each frame.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

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

Assigning a mesh through script 1 Answer

Can't Make Mesh Display Using Quill18 Tilemap Tutorial (Boo conversion) 0 Answers

Mesh Filter Cosmetic Damage 1 Answer

Query if MeshFilter is instantiated or shared? 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