combining submesh

I have a mesh with multiple submesh. Depending on what the user picks I am combining different submesh and excluding the others.

At this point I am just trying to combine the submesh and add them into submesh 0 then set my submeshcount to 1, but I am failing.

Any help would be appreciated:

MaterialCount = mesh.subMeshCount;
pkeep = new Array ("1","3","30");
submesh= new ArrayList ();
		
for( m = 0; m < MaterialCount; m++ ){
	for (i=0; i<pkeepmural.length; i++){
		if (m.ToString().Contains(pkeep[i])){
			s =  mesh.GetTriangles(pkeep[i]);
			submesh.Add(s);
		}
	}
}
mesh.SetTriangles(submesh,0);

I get:

MissingMethodException: Method not found: ‘UnityEngine.Mesh.SetTriangles’.

I changed it a little because I realized that contains would find more than what I want.

I also tried to convert the ArrayList to an int, but it still fails.

Any help would be appreciated… :slight_smile:

		for( m = 0; m <= MaterialCount; m++ ){
			for (i=0; i<pkeep.length; i++){
				if (int.Parse(m.ToString()) == int.Parse(pkeep[i].ToString())){
					s = mesh.GetTriangles(int.Parse(pkeep[i].ToString()));
					submesh.Add(s);
				}
			}
		}
		mesh.subMeshCount = 1;
		mesh.SetTriangles(submesh.ToArray(typeof(int)),0);

Here is the error on this latest piece of code:
InvalidCastException: Cannot cast from source type to destination type.

I think AddRange is what I want… that worked I just have to fix my code to add everything correctly. I’ll post back if I fail again.