• 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
Question by Doyle Dice · May 19, 2014 at 06:08 PM · meshmeshfiltermesh-deformationsharedmesh

Cannot using two script to modify the same mesh at the same time

I have one script for modify a mesh's shape.that script attached in a prefab.the shape will change more depends on the distance between the shape and the prefab.i place one prefab and play,it will fine. But when I place another prefab,only the first one work....?

the code is something like this:

 plane=GameObject.Find("default");
 m=plane.GetComponent().mesh;
 m.MarkDynamic();
 va=m.vertices.Clone() as Vector3[];

and then use a for loop to change the vertex's position "y" which is close to the prefab. finally:

 m.vertices=va;
 m.RecalculateNormals();

in the scene,only one prefab can change the mesh as the same time....

EDIT:

i using Debug.Log to trace which vertex has been changed by which Prefab.and the result point out that both Prefab read the same mesh vertex array and success modify them.however,i guess this line:

m.vertices=va;

only one prefab success to apply the changed vertex[] back to the plane'mesh.

Now two prefab name is "Cube1" and "Cube2",if i add this in the script:

 if(gameObject.name=="Cube1"){
  m.vertices=va;
  m.RecalculateNormals();
  }

only Cube1 will work, if the name change to "Cube2",only Cube2 work. but remove the "if statement",can't see both work......

Comment

People who like this

0 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 fafase · May 19, 2014 at 06:09 PM 0
Share

You need to edit your question to add the code. Without it, we can just assume possible errors.

avatar image Loius · May 19, 2014 at 06:12 PM 0
Share

I assumed but I already know I'm an ass. :3

1 Reply

  • Sort: 
avatar image

Answer by Loius · May 19, 2014 at 06:11 PM

Use .mesh instead of .sharedMesh so each object gets its own copy.

Comment
Doyle Dice

People who like this

1 Show 0 · 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta on June 13. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

Procedural Mesh problem from Editor Window 1 Answer

Query if MeshFilter is instantiated or shared? 1 Answer

Mesh.vertices are all 0? 1 Answer

Create runtime 3D mesh and Fill area like Paper.io 2 1 Answer

Problem with setting vertices positions and smoothing groups. 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