- Home /
Error: Material doesnt have texture property.
I am trying to change my materials textures and am getting the following error (and a similar one for _LightMap):
Material doesn't have a texture property '_MainTex4'
UnityEngine.Material:SetTexture(String, Texture)
UnityEngine.Material:SetTexture(String, Texture)
tile_container:Change_Tile() (at Assets\Scripts\tile_container.js:94)
tile_container:tile_container$Change_Tile$(Object, Object[])
System.MulticastDelegate:invoke_object_object_object[](Object, Object[])
Boo.Lang.Runtime.RuntimeServices:Dispatch(Object, String, Type[], Object[], DispatcherFactory)
Boo.Lang.Runtime.RuntimeServices:Dispatch(Object, String, Object[], DispatcherFactory)
Boo.Lang.Runtime.RuntimeServices:Invoke(Object, String, Object[])
UnityScript.Lang.UnityRuntimeServices:Invoke(Object, String, Object[], Type)
SaveLoad:Load_Map() (at Assets\Scripts\SaveLoad.js:151)
I just cant figure out why. The shader looks like this:
Shader "World Multi Texturing" { Properties { _MainTex0 ("Base 0 (RGB)", 2D) = "white" {} _MainTex1 ("Base 1 (RGB)", 2D) = "white" {} _MainTex2 ("Base 2 (RGB)", 2D) = "white" {} _MainTex3 ("Base 3 (RGB)", 2D) = "white" {} _MainTex4 ("Base 4 (RGB)", 2D) = "white" {}
_BlendTex ("Blend (RGB)", 2D) = "black" {}
_LightMap ("Light (RGB)", 2D) = "white" {}
}
SubShader
{
Pass
{
Lighting On
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
uniform sampler2D _MainTex0;
uniform sampler2D _MainTex1;
uniform sampler2D _MainTex2;
uniform sampler2D _MainTex3;
uniform sampler2D _MainTex4;
uniform sampler2D _BlendTex;
uniform sampler2D _LightMap;
struct v2f
{
float4 position : POSITION;
float3 normal : COLOR;
float2 texblend : TEXCOORD0;
float2 texcoord : TEXCOORD1;
};
v2f vert(appdata_base In)
{
v2f Out;
Out.position = mul(glstate.matrix.mvp, In.vertex);
Out.normal = mul(_Object2World, float4(In.normal, 0.0f)).xyz;
Out.texblend = (mul(_Object2World, In.vertex).xz+4.0f)/256.0f;
Out.texcoord = In.texcoord.xy;
return Out;
}
half4 frag(v2f In) : COLOR
{
float4 color0 = tex2D(_MainTex0, In.texcoord);
float4 color1 = tex2D(_MainTex1, In.texcoord);
float4 color2 = tex2D(_MainTex2, In.texcoord);
float4 color3 = tex2D(_MainTex3, In.texcoord);
float4 color4 = tex2D(_MainTex4, In.texcoord);
float4 blend = tex2D(_BlendTex, In.texblend);
float4 light = tex2D(_LightMap, In.texblend);
float4 color = lerp(color0, color1, blend.r);
color = lerp(color, color2, blend.g);
color = lerp(color, color3, blend.b);
color = lerp(color, color4, blend.a);
In.normal = normalize(In.normal);
float diffuse = 0.5;
diffuse += saturate(dot(normalize(float3(1.0f, 1.0f, 1.0f)), In.normal));
return half4(color.rgb*light.rgb*diffuse, 1.0);
}
ENDCG
}
}
FallBack "Diffuse"
}
There are no textures assigned, before I do so within the script like this:
tile_script.instance.renderer.materials[0].SetTexture("_MainTex4", tiletex4);
The textures are created like this:
var imagebytes : byte[] = File.ReadAllBytes(filepath);
tiletex4.LoadImage(imagebytes);
Is there a maximum texture limit other than the one of my hardware? Please help me to fix this if you can :) Thanks.
Answer by JonManatee · Jul 02, 2010 at 06:49 AM
Limits are also imposed by shader profiles, although I don't know if that specifically is your problem, it does answer your last question. See: http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter01.html
See specifically the statement in the section about profiles that:
For example, a given fragment profile may limit you to no more than four texture accesses per fragment.
and also see:
http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter10.html
for in-depth info on profiles
Thanks for your answer, I will try to compile for shadermodel 3.0 ins$$anonymous$$d, as that would mean a higher profile with an endless number of texture fetches, right? I just wonder why the script and not the shader is complaining. And why it works fine, while still throwing those errors.
Your answer
![](https://koobas.hobune.stream/wayback/20220613063155im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple materials on same object 0 Answers
Texture2D to Texture3D 2 Answers
Tracing in Unity3D 2 Answers
What is wrong with my shader? 1 Answer