- Home /
Changing HDRP Material's Texture At Runtime Not Working?
I've tried:
mat.mainTexture = texture;
//or
mat.EnableKeyword("_BaseColorMap");
mat.SetTexture("_BaseColorMap", texture);
I've even made a custom shader in Amplify with a custom texture property, and it still wouldn't work.
I'm using this to get the material of the object:
Material mat = obj.GetComponent<MeshRenderer>().material;
Any idea why this wouldn't be working?
Edit: I'm using 2019.4.11f1 by the way.
Edit 2: Tried this as well.
Shader shader; //using created Shader
var mr = obj.GetComponent<MeshRenderer>();
var mat = new Material(shader);
mat.mainTexture = texture;
mr.material= mat;
Answer by CameronMorrow · Oct 05, 2020 at 09:37 PM
You could try this:
Shader shader; //using the shader you created
var mr = obj.GetComponent<MeshRenderer>();
var mat = new Material(shader);
mat.mainTexture = texture;
mr.material= mat;
//or
var mr = obj.GetComponent<MeshRenderer>();
mr.material = texture;
I have had issues with the materials because of how they need to be assigned, and the specific order of things.
Ya i've tried this too, unfortunately..
I have no idea why its not working. It works on the Built-in Render Pipeline but it's not working at all with HDRP for some reason.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to Properly create & apply a normalmap and specular? (Hard Surface Shader Free) 2 Answers
Blend 2 linerender colors at point of interception 0 Answers
Best method for implementing alternative view modes? (like Cities: Skylines "Info View") 0 Answers