Right now I have a model with one of its mesh renderers using an unlit color shader to show the character is “empty” as it were and my intent is to have it display a proper material through the script (through the pressing of a button should this problem be fixed). While the script assigns the material as it should in the editor, in the build it drops the textures that are on the material entirely and I have no idea why.
Here’s what the model looks like naturally
Here’s what it looks like when built (For the purposes of this thread I created an identical material that is tinted red to highlight a point later)
And this is what it looks like in the build
As you can see the material is loading in the build as the red property is still there. For whatever reason, though, the diffuse texture and the normal map that are also suppose to be on the material are nowhere to be seen. For whatever reason, though, when I change the “Generic” shader used for the body from being an unlit shader to a standard shader everything works fine (I, of course, do not want to use a standard shader for this).
This is the line of code that’s suppose to assign the material to the model
//"armor" is a public material that I dragged and dropped into the property box
GetComponentInChildren<SkinnedMeshRenderer>().material = armor;
So what’s the problem? Do I need more code or is there something in the build settings I need to do for the textures and normals on the material to show up on the build? Or could it be a problem with the texture itself?
Look in the Inspector of hte material (your first image). There is no texture slot on the right so this shader will not display any textures.
You selected “Unlit/Color”. What you want is “Unlit/Texture”.
I changed it to an unlit texture shader and it most certainly works now, but why? I don’t understand why that would make any difference when, the way I understand the code, I’m swapping out one material for a completely different one. Likewise the texture shader doesn’t let me change the color of the unlit material (unless I’m meant to just create a blank purple square and implement that as a texture). Is there a way for me to still do that without creating a custom shader that combines the two (or does creating a blank purple square actually work?).
EDIT: Making a blank purple texture does indeed allow me to change the color, but I still don’t understand why changing the shader from unlit color to unlit texture solved the problem.
When you would change the shader to Unlit in the editor, there also is no texture. Unlike the standard Shader the Unlit shader, and basically every other, have one specific set of features. Usually, if the inspector doesn’t show a property, like a texture field, then the shader is not capable of drawing it.
The Unlit/Color shader does only display a color, it does not sample any texture. If you need no texture then you save rendering power by using it. Then there is the Unlit/Texture shader which just displays the texture but without a color property, so you can’t tint it. All the Unlit shaders are very minimal but efficient.
So yes you would have to make your own Unlit Shader that also supports color tint. Here seems to be one.