Vertices is always out of bound - Mesh and submesh

I get this error;

Failed setting triangles. Some indices are referencing out of bounds vertices. IndexCount: 6, VertexCount: 6
UnityEngine.Mesh:SetTriangles(Int32[ ], Int32)

I don’t know where the error is coming from but, i get this this error only two time out of 3. (2rd and 3th, SetPixelUpdate())

This is hard to explain so here’s the script… [Pastbin File]

Don’t forget, i speak french.

Maybe its using the wrong array count for triangles?

// original
tri[0] = vertices.Count + 0; //0 //0

// try
tri[0] = verticles.Count + 0; //0 //0

it’s not working because “vertices” is not an array, array can’t use Count; I will explain my goal.
I use SetPixelUpdate for create an pixel at X and Y position. The ColorId string is used for get the submesh. Each submesh have it’s own materials, exemple: SetPixelUpdate(0, 0, “Red”); The program will find the submesh id witch is assing with the red material. My problem is the SetTriangle function doesn’t work…

Adding mf.mesh.Clear(); to end of ResetScreen() seems to remove the error at least.

1 Like

WOAH! All the pixels are there but these have no any color.
ResetScreen();
SetPixelUpdate(1,1, “Red”);
SetPixelUpdate(1,2, “Blue”);
SetPixelUpdate(1,3, “Green”); turn into Black Black Black.

I will try to fix that.

After hour and hour of searching, i found this; all the triangles are default added to the first submesh, how to avoid this?

  1. You are not setting any normals. That seems to be the problem for the colors.
  2. I can’t quite understand what you mean by, all the triangles are added in the first submesh by default. I will test it when I have more time, and I’ll come back with some feedback.
1 Like

All triangles are added into the default submesh but the default submesh is black. I think that is why pixles are all black. I’ll me too try to invert black with another color for see if the color change.

After testing, if i place black at the blue and blue at the black, red blue green, turn into blue blue green.

Maybe it will work if i create an “empty material” submesh, all triangles will by default added in this be submesh but, this submesh have no materials, so the main (red, blue, green, yellow and else) will give a color to the pixel. Again, sorry for extremely bad english :stuck_out_tongue:

Half working, new pixels delete the old pixels from the submeshs, result; old pixel have no color.

The first triangle is red. Second are blue and green. The red submesh triangle count; 1:6 2:0 3:0…