Hello, I am trying to create a RenderTexture of the image below to eventually create a Texture2D that can be used in an sprite atlas later. I have found various tutorials and have come up with the following code:
private Texture2D CreateAtlasTexture(int textureSize)
{
RenderTexture renderTexture = new RenderTexture(textureSize, textureSize, 24);
Texture2D atlasTexture = new Texture2D(textureSize, textureSize, TextureFormat.ARGB32, false);
RenderCamera.aspect = 1.0f;
RenderCamera.targetTexture = renderTexture;
RenderCamera.Render();
RenderTexture.active = renderTexture;
atlasTexture.ReadPixels(new Rect(0.0f, 0.0f, textureSize, textureSize), 0, 0);
RenderTexture.active = null;
RenderCamera.targetTexture = null;
return atlasTexture;
}
However, when I run this code, and the camera preview looks like the screenshot below, I get a Texture2D that is 100% gray. Can someone help identify why this might be happening?