get pixel of texture filled in external plugin

Hello,
I have an external plugin which fills texture created in Unity.
I managed to display the texture in Unity (via shaders), but I cannot get the color of a pixel via script.

Here is the code I use.

 //get raw data from the camera
byte[] b = cam.GetRawTextureData();
//Create a new texture to read pixels
Texture2D t = new Texture2D(cam.width, cam.height, TextureFormat.RGBA32, false);
//Load data to new texture
t.LoadRawTextureData(b);
//display 205 205 205 205
Debug.Log(t.GetPixel(1, 1));

Do you have any idea why I cannot read a color ?

Thanks

Try calling t.Apply() after t.LoadRawTextureData().

It gives the same values

No one knows?

Did you enable the Read/Write flag in the import settings of the texture?. Without that this function falls.

This texture is created via script, how to enable the read/write via script ?

And apparently “A Texture2D is always readable and writable. For a Texture object, the read/write enabled option can only be set in the import options.”

up

Don’t just “up”. Provide more detail. Why can’t you read a texture? What happens when you try? How is what happens different from what should happen? Does this only happen with textures loaded with that plugin? What format are these textures in (which may differ from the ARGB32 with which you created the texture object).

I can tell you that I read pixels from textures all the time, and it works for me… so, provide enough detail and maybe we can help.

When I try to read a texture, I have the same values which appear (205,205,205). Whereas the texture comes from a webcam, and the image is well displayed on a texture. My texture is in the format RGBA32

What do you see when you inspect the raw data (“b” in your code above)? Is it actually changing from frame to frame, or is it always the same?

it’s always the same

In that case, the problem has nothing to do with Texture2D; it’s in your camera plugin. You’d better pursue it with whoever makes that.