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
1
Question by ffxz7ff · Nov 16, 2013 at 03:03 AM · meshinvisiblemodifyafter

Mesh goes invisible after modifying vertices

Hello,

I have a mesh whose vertices I'm modifying at runtime by script. After I modify them, the mesh goes invisible, and I'm clueless about the why. The modification of the mesh works alright, I can see that when I pause the editor and click at the gameobject in the list. It just won't display.

A MeshRenderer is attached and it displays fine before the modification.

The mesh contains several submeshes (maybe that's important?).. Before and after the modification of the vertices, the object properties looks exactly the same in the inspector, with all materials and components applied.

Here's some code (simplified):

 mesh = go.GetComponent<MeshFilter>().mesh;
 vertices = mesh.vertices;
 
 tempVector = new Vector3(x, c1, z);
 vertices[0] = tempVector;
 
 tempVector = new Vector3(x, c2, z);
 vertices[1] = tempVector;
 
 tempVector = new Vector3(x, c3, z);
 vertices[2] = tempVector;
 
 tempVector = new Vector3(x, c4, z);
 vertices[3] = tempVector;
 
 mesh.vertices = vertices;
 go.GetComponent<MeshFilter>().mesh = mesh;



Any idea anyone? Thanks.

EDIT: Attaching two screenshots. Those 3 chunks in the background haven't had their meshs modified, the other one did.

Other than that they're the same, instantiated from a prefab. Only the Y-values of the vertices have been changed. The mesh is there, just invisible.

alt text

alt text

chunk1.jpg (68.9 kB)
chunk2.jpg (95.2 kB)
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 ffxz7ff · Nov 16, 2013 at 12:20 PM 0
Share

Any suggestions what I should be looking for? I'm out of ideas.

avatar image ffxz7ff · Nov 16, 2013 at 10:27 PM 0
Share

No idea, I suppose?

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by aldonaletto · Nov 16, 2013 at 03:31 AM

Maybe the vertices are becoming reversely wound after modified. Remember that the front face of a triangle is defined by its winding order: the front face is the one where the vertices are in clockwise order. Modifying the position of a single vertex may make the triangle face the opposite side, like below:

alt text

Another possibility is the triangles becoming empty (when the 3 vertices are in the same line).


backfacedtriangle.png (4.4 kB)
Comment
Add comment · Show 5 · 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 ffxz7ff · Nov 16, 2013 at 07:29 AM 0
Share

Thanks for the reply. I don't think that's it though, because I only change the height (Y) coordinate of the vertices so the winding order should still be the same, and I can't see the mesh's textures from the other side either.

I modified meshes before without this issue, the only difference that I know of this time is the existence of submeshes. I wonder if it has something to do with that. $$anonymous$$aybe it resets some other array when I change the mesh.. the vertices.length stays the same though so I'd doubt that.

avatar image ffxz7ff · Nov 16, 2013 at 09:25 AM 0
Share

Hmm no, it isn't resetting any arrays either.

avatar image aldonaletto · Nov 16, 2013 at 10:56 PM 0
Share

Actually, modifying the vertex position doesn't change its order in the triangle, but may reverse its front face - although this would make the inner side visible, what isn't happening. What about renderer.bounds? If badly calculated, it may become null or out of view, what would cull the mesh out during frustum culling.

avatar image ffxz7ff · Nov 17, 2013 at 10:11 AM 0
Share

I recalculated the bounds, that didn't help either.

But I think this is an issue of the past anyway. I finally stumbled upon the Terrain class (ugh), so I guess I was wasting my time by building a mesh map anyway.

Would upvote for your help if I could.

avatar image CHPedersen · Jan 05, 2015 at 09:12 AM 0
Share

I don't know what was wrong with your mesh, but I have the power to upvote both of you. ;) The question for being well-phrased and supported with images, and the reply for much the same qualities.

avatar image
0

Answer by piottej · Jan 05, 2015 at 09:13 AM

Hi guys, I'm having the exact same issue with various meshes I modify. I only change the vertices positions. I checked several times and I can't see my mesh from any point of view in the scene.

Same as aldonaletto, I recalculated the bounds of the mesh and the normals through script after deformation.

One more piece of information : If I check/uncheck any toggle in the renderer component window (eg "CastShadows", "Receive Shadows") or if I uncheck and recheck the MeshRenderer Component, my mesh becomes visible.

Another piece of information. I used to do my mesh modifications in a corroutine started by a manager behaviour. This manager used to check all the meshes that could need a distortion. But I changed this to trigger the modification at runtime in the "OnBecameVisible" method to optimize my app a bit. (Instead of having to check all meshes everytime I can, I only check the meshes that become visible) I didn't have the issue before. I checked several times and I don't see anything else changed in my code than moving my distortion from the corroutine to the OnBecameVisible method.

The issue seems to be related to some kind of renderer refresh. I really need to deform meshes at runtime for my app. FYI I tried to disable & re-enable the mesh renderer component through script after applying the modification to my mesh to see if this triggers some kind of refresh or whatever. It seems to work, my meshes seems to always be visible. But this is so ugly to have to do that... Does anyone has an idea of how to solve this ?

EDIT : Btw, I'm not quite sure if I had to post an "answer" or a "comment" to resurrect this thread to get my answer. Feel free to tell me if this should be a comment and I'll remove this answer to put it as comment. And Sorry for my poor level of english :(

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

19 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

Related Questions

Why my Rock Meshes are invisible in the scene and visible in the game? 3 Answers

invisible mesh in game mode 1 Answer

All GameObjects are now invisible! How do I get them back? 2 Answers

Modify a mesh at runtime 0 Answers

Refresh/Reload Model From Assets Folder Each Frame? 3 Answers


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