• 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 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
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 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

· Add your reply
  • Sort: 
avatar image
1

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

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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

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

Replace MeshFilter mesh by a other mesh in Editor 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