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

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

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

the object of type rigidbody has been destroyed 3 Answers

Canvas Problem 1 Answer

Can't Establish connection using NetworkTransport 0 Answers

Help "Too many threads" 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges