So wait, how is Texture2D.GetPixels() supposed to work?

I do this:

        sourceTexture = zedCam.CreateTextureImageType(sl.VIEW.DEPTH);
        material.mainTexture = sourceTexture;
        Color[] pixels = sourceTexture.GetPixels();

And pixels is filled with identical grey values for every pixel in sourceTexture. If I apply sourceTexture to a material, as shown in line 1, it looks correct. It is a black and white depth map from a camera feed.

I’ve tried iterating with GetPixel instead, same result. Also tried using GetPixels32 and a Color32 array. Also tried Color[] pixels = sourceTexture.GetPixels(0,0, sourceTexture.width, sourceTexture.height, 0) for the third line.

I’m doing this because I need the gray-scale values from sourceTexture.

Have you marked the texture as readable in the import settings?

Is there a way to do that on a texture generated at run-time? Line 1 above is storing a texture generated by a live camera.

Nevermind. Apparently my first line is creating a texture on the GPU, which would not be accessible to GetPixels. I’ll need to write a compute shader to get at it.