RenderTexture newTex = new RenderTexture(256, 256, 0);
Material newMat = new Material(Shader.Find("Diffuse"));
newMat.SetTexture("_MainTex", newTex);
I get
Error assigning 2D rectangle texture to 2D texture property '_MainTex': Dimensions must match
It doesn't matter what dimensions I specify, not to mention that the Material should have no dimensions until I give it a texture. What exactly is it that doesn't "match"?
Even weirder: The code runs fine if I ignore the error (so it's more like a warning)... But I despise leaving warnings in my code.
For some reason, you must tell Unity whether this is a power of two texture or not. The following sequence of lines prevents the error.
RenderTexture newTex = new RenderTexture(1024, 1024, 0);
newTex.isPowerOfTwo = true; // This line prevents the error
newTex.Create(); // This line is totally optional
I believe that instantiating a RenderTexture does not actually create the texture -- that happens after it is first rendered or Create() is called. Perhaps adding a call to Create() before assigning it to the material would get rid of the error.