Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 danp · Mar 19, 2021 at 11:58 PM · meshverticesmeshfilter

Can't change verts on mesh after assigning to meshfilter.

alt text

I'm editing the verts in my hex meshes to deform them. The hexes are working fine but I'm unable to change the water hexes and I'm not sure why. The land hexes are instantiated prefabs with the mesh already assigned. The water hexes I use this to get the mesh.

             Transform obj = waterHexMeshes.transform.Find(meshName);
             if (obj) {
                 clientHex.meshFilter.mesh = obj.GetComponent<MeshFilter>().sharedMesh;
             }

This is used to deform the mesh. This runs on all the hexes both water and land.

     public void DeformMesh() {
         List<Vector3> verts = new List<Vector3>();
         meshFilter.mesh.GetVertices(verts);
 
         for (int v = 0; v < verts.Count; ++v) {
             // find which corner vert belongs to by find which Hex.CornerOffset it's closest to
             int index = 0;
             float distance = 999999f;
 
             for (int c = 0; c < 6; c++) {
                 Vector2 cornerPos = Hex.CornerOffset(c, SettingsStatic.hexRadius);
                 float dist = Vector2.Distance(cornerPos, new Vector2(verts[v].x, verts[v].z));
 
                 if (dist < distance) {
                     distance = dist; 
                     index = c;
                 } 
             }
 
             verts[v] += new Vector3(cornerOffsets[index].x, 0f, cornerOffsets[index].y);
         }
 
         meshFilter.mesh.SetVertices(verts);
     }

This line.

 meshFilter.mesh.SetVertices(verts);

Does not work on the water hexes but does on the land hexes. I do not understand why. Both meshes are marked as read/write. The only difference is the water hex meshes are assigned to the meshfilter and the land hexes are assigned in the unity editor.

screenshot-2021-03-19-165154.jpg (29.7 kB)
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
0

Answer by danp · Mar 20, 2021 at 12:37 AM

I solved my problem by copying the vertex colors instead of the mesh.

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

127 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 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 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 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 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 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 avatar image

Related Questions

Creating a mesh for an overview map 0 Answers

Number of mesh vertices increase when imported into unity 1 Answer

Save only visible part of mesh 1 Answer

Mesh.vertices are all 0? 1 Answer

Get all vertices in gameObject to array. 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