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;

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.

Same problem…