Is there a way to find out if a material has a texture (or other property) by name without getting a runtime error?
I am trying to get a “_BumpMap” texture if one exists and avoid an error if one doesn’t exist. However, calling GetTexture(“_BumpMap”) gives me a runtime error if it doesn’t exist.
It’s interesting that in the documentation page for Material.GetTexture (http://unity3d.com/Documentation/ScriptReference/Material.GetTexture.html), they give the following sample code:
function Start ()
{
var tex = renderer.material.GetTexture("_BumpMap");
if (tex)
print ("My bumpmap is " + tex.name);
else
print ("I have no bumpmap!");
}
Which does work and prints “I have no bumpmap!”, but also gives a “Material doesn’t have a texture property ‘_BumpMap’ UnityEngine.Material:GetTexture(String)” on the GetTexture() line.
From the nature of the problem, I could assume that the Shader class would have a isTextureSupported() function or something like that.
Note that this is only a problem when the Shader doesn’t have the “_BumpMap” property, not when the shader has the capability, but the bumpmap is none in the editor.