- Home /
Mesh Renderer Matereal Aray reduce?
Ok, the problem. The description of it is a long one.
Fist off, all of this is going on in run-time.
I am using a script that uses a boolean operation on two objects, each with their own separate materials.
What it does is something like a CSG subtraction operation, only it cuts into the faces of object 1 in the shape of object 2, but instead of leaving behind the faces of object two to fill in the hole as a solid hole with the material of object 2 and its left over mesh, all of object 2 is removed, leaving an empty hole in the mesh of object 1. This is what I want. And it works great! But with one exception.
Object 1's mesh now shows to have two submeshes (just as the regular CSG subtraction operation would create), and the Mesh Renderer shows to have 2 in the materials array size with two elements in it. One for each material form each object. Even though object 2 is supposed to be subtracted completely.
Problem, the actual mesh to submesh 2 in object 1 is missing and I get a repeating srcIB error in my Console window that counts up quickly.
Now if I go into the the inspector during run time, and set in the Mesh Renderer's element 2 spot to have "None" for material, or just set the Mesh Renderer's material array size to just 1, either option stops the srcIB error.
OK, so what I want to do should be very simple, but I have yet to find an answer. It is to somehow pullout a copy of the Mesh Randerer's material array in object 1, and change it to have only 1 element/ or that is one index, then pass in the copied Mesh Randerer's material array to change it to have just the 1 index to stop the srcIB error I keep getting during run-time.
I just don't know how to do that operation yet?
To pass out a copy of the Mesh Renderer, change/or create the material array index in the copy to just 1, with the material in index 1 still intact, then set object 1's Mesh Renderer to that copy.
How does one do this in a run-time script? It is so easy to change Mesh Renderer material array index count in the inspector, but not easy at all to do in script, as I found.
Does anyone have the very solution to change the array size of the Mesh Renderer's materials list shown in the inspector to a gameobject, but do it with a C# script?