How do I set a material on prefab during instantiation?

What is the correct way of assigning / changing a texture on a prefab as it’s being instantiated?
I’ve been trying to use the same logic that I’m applying to change a texture on collision (which works perfectly in that scenario):

hit.gameObject.renderer.material.mainTexture = someTexture;

Like:

prefabVar = Instantiate(prefabArray[i]); 
prefabVar.renderer.material.mainTexture = someTexture;

This gives me some really weird results like meshes not rendering at all or ignoring transformations added later etc. (some of the prefabs actually show up with the right texture, but ignoring all transformations). The prefabs in question are all set as children of another gameObject that I’m applying some transformation too (dunno if this is relevant or not)

I had a problem like this. I had to create a second gameobject variable, assigned the instantiated prefab to that second object, then assigned a material to the second. I think what happens is, when you instantiate a prefab, then mess with the material on the cloned object, you are, essentially, messing with the prefab’s material. It is something like that.

It might be relevant - can you explain in more detail what you are doing with the GameObjects?