- Home /
Changing Texture of Material of Meshrenderer creates Instance in Start() but not in Update(), just see blue dots
I am setting a new 3D Texture via .SetTexture() to the Material in Meshrenderer. However it only creates an instance of the material, which looks odd. But the Material in my assets folder is changed correctly. But when I assign the Material in Update() it works. When I do it in Start() I just see blue dots, so something was updated but not correctly I guess. I have already tried sharedMaterial instead of Material
My code (unnecessary parts are left out):
//volumeRenderMaterial is the original Material on which I want to change the texture
//volume is a 3D texture created at runtime in Start()
volumeRenderMaterial.SetTexture("VolumeTex", volume);
GetComponent().material = volumeRenderMaterial;
Answer by KloverGames · Nov 18, 2021 at 01:05 PM
You have to add GetComponent().material = volumeRenderMaterial; before volumeRenderMaterial.SetTexture("VolumeTex", volume). The code is executed from top to bottom. You're setting the texture before you get the material component.
So do it in this order
void Start()
{
GetComponent().material = volumeRenderMaterial;
volumeRenderMaterial.SetTexture("VolumeTex", volume);
}
I have also tried this, this does not do the trick, unfortunately.
My code would be correct, you’re probably missing something in the editor/hierarchy. Just try to look at anything you might be missing
I have forgot to mention that I see blue dots instead of the texture, so something changed but apparently there goes something wrong
Make sure the texture itself is correctly setup in the Assets folder as well