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
0
Question by Xyotic · Mar 04, 2015 at 04:10 PM · unity 5errormeshcollidergenerationsubmesh

Unity5 - "Failed getting triangles"

In my project I'm generating differnet meshes all useing submeshes. Before Unity 5 all the meshes generated without problems. But now it there is a problem wich appear before generating the meshcollider. It says in the console:

"Failed getting triagles. Submesh 1 has no indices. UnityEngine.MeshCollider:set_sharedMesh(Mesh)",

this error applies to every submesh. The mesh itself generates. But the meshcollider won't. Does anyone have an Idea how to fix this? (My english isn't perfect sry ^^' )

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 0V3RR1D3 · Mar 04, 2015 at 04:43 PM 0
Share

Are you passing the right mesh? Did you set the vertices?

avatar image Xyotic · Mar 04, 2015 at 06:40 PM 0
Share

Yes. As I said it worked perfectly in Unity 4.6

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by syruf · Jun 17, 2015 at 06:27 AM

I was encountering this error when adding a mesh collider component to a gameobject that had a meshfilter with an empty submesh that i set by mesh.SetTriangles(). One way to prevent an empty submesh would be to omit the submesh entirely, as some of the answers here suggest. That was difficult to handle in my case because I would have to later omit the material from the respective meshrenderer elsewhere in scripts.

Instead, while using mesh.SetTriangles(), i check if the submesh is empty and if so just give it a placeholder triangle with the first vertex (0,0,0). It may cause conflict for some cases but its working okay in my game.

 mesh.SetTriangles(subTriangles.ToArray(),subindex);
 if(mesh.GetTriangles(subindex).Length < 3){
   mesh.SetTriangles(new int[3]{0,0,0},subindex);
 }


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
0

Answer by bostich83 · Mar 05, 2015 at 12:02 AM

I just had the very same issue today.

Make sure your index count is always > 0.

 int subMeshCount = 0;
 if(triangles0.Count>0){
   mesh.SetTriangles(...)
   subMeshCount++;
 }
 
 mesh.subMeshCount = subMeshCount;


Hope that helps!

//bostich

//edit:

And don't forget to reduce the material's according to your submeshCount, looks funny otherwise :)

Comment
Add comment · Show 10 · 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 Xyotic · Mar 05, 2015 at 12:28 AM 0
Share

This doesn't work for me. :( This is how my code looks now:

 int sub$$anonymous$$eshCount = 0;
 
         if(tris1.Length > 0) {sub$$anonymous$$eshCount++; mesh.SetTriangles(tris1, 0);}
         if(tris2.Length > 0) {sub$$anonymous$$eshCount++; mesh.SetTriangles(tris2, 1);}
         if(tris3.Length > 0) {sub$$anonymous$$eshCount++; mesh.SetTriangles(tris3, 2);}
         if(tris4.Length > 0) {sub$$anonymous$$eshCount++; mesh.SetTriangles(tris4, 3);}
         if(tris5.Length > 0) {sub$$anonymous$$eshCount++; mesh.SetTriangles(tris5, 4);}
         if(tris6.Length > 0) {sub$$anonymous$$eshCount++; mesh.SetTriangles(tris6, 5);}
         if(tris7.Length > 0) {sub$$anonymous$$eshCount++; mesh.SetTriangles(tris7, 6);}
         if(tris8.Length > 0) {sub$$anonymous$$eshCount++; mesh.SetTriangles(tris8, 7);}
         if(tris9.Length > 0) {sub$$anonymous$$eshCount++; mesh.SetTriangles(tris9, 8);}
 
         mesh.sub$$anonymous$$eshCount = sub$$anonymous$$eshCount;
avatar image bostich83 · Mar 05, 2015 at 08:43 AM 0
Share

I think that's because your meshIndex is wrong:

 int sub$$anonymous$$eshCount = 0;
 int meshIndex = 0;
 if(tris.Length > 0) { sub$$anonymous$$eshCount++; mesh.SetTriangles(tri1,meshIndex++)}

That's untested though, because my mesh setup is not as complex as yours ;)

//bostich

avatar image Xyotic · Mar 05, 2015 at 10:30 AM 0
Share

I've tried that but it still doesn't work. The problem has to be something different. It's really strange because with the old code it generates the mesh correctly. Only the meshcollider doesn't work.

avatar image bostich83 · Mar 05, 2015 at 10:39 AM 0
Share

After doing all that above i do the following:

 mesh.Optimize();
 collider.shared$$anonymous$$esh = mesh;

but, it should work even without optimize.

$$anonymous$$b you can post more code on pastebin? Really wondering why that is not working for you.

//bostich

avatar image Xyotic · Mar 05, 2015 at 11:09 AM 0
Share

This also didn't help. This is the original code I'm using to create the hole mesh. Link

Show more comments
avatar image
0

Answer by primemover · Mar 22, 2015 at 05:23 PM

You should paste your code again, that link you have above isn't working.

I was able to fix my issue, and without Optimize(). I have my triangles in an array of integer lists, so I iterate through those to set triangles for the proper material. I just had to have a counter that iterated if that material had any triangles associated with it, if it did I set triangles, but at the same time, I rebuilt my materials array. I do this for each chunk as each chunk would have a different set of materials.

 int subMeshCounter = 0;
 materialList.Clear();
 
 for (int x = 0; x < trianglesListArray.Length ; x++)
 {
     if (trianglesListArray[x].Count > 0)
     {
         chunkMesh.SetTriangles(trianglesListArray[x].ToArray(), subMeshCounter);
         materialList.Add(MainGame.maingame.CurrentWorld.Materials[x]);
         subMeshCounter++;
     }
 }
 chunkMesh.subMeshCount = subMeshCounter;
 
 GetComponent<Renderer>().materials = materialList.ToArray();
 
 chunkMesh.RecalculateNormals();
 chunkMesh.RecalculateBounds();
 chunkMeshFilter.mesh = chunkMesh;

 chunkMeshCollider.sharedMesh = null;
 chunkMeshCollider.sharedMesh = chunkMesh;


Don't know if any of that helps, if not post your code again.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity 5 - submeshes don't work as before 1 Answer

Generate Colliders not working on FBX imported object 1 Answer

PrefabUtility does not exist? 1 Answer

Object Refrence Not Set To An Instance Of An Object? 2 Answers

Unity 5.6 upgrade pains 0 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