Does anyone know how to store pixel info from a texture in unity into an array in MonoDevelop?

Hello !

I’ve seen many Unity Answers articles that have info related to this question, but none of them have resolved my problem. I made a texture in paint and exported it as a Jpeg. Then I dragged the texture onto a plane in unity. All of this worked out, but now I want to store the pixel information into an array in MonoDevelop using the Texture2d class method getPixels32(). My problem is that when I try to access the texture using

myTexture = plane.GetComponent ().material.mainTexture;

it won’t work because this returns a texture value, whereas my variable myTexture is in the Texture2D class. I can’t get pixel info if I use the Texture class so it has to be Texture2D. In the Unity Scrip API it says that the Texture2d class can be used to “modify existing texture assets”, but I can’t figure out how to bring my texture information into MonoDevelop as Texture2D objects. I’ve been through the Unity docs and have read many articles, but I haven’t found anything that was able to resolve my issue. Much thanks for any help I can get.

Best
Alex

If you are getting an error it is because in the texture import settings you need to make sure “read/write” is checked.

If you created this image in paint, why are you trying to retrieve it from a plane? make public variable,

public Texture2D myTexture;

and then just drag your jpg from your assets folder to that slot.

if you absolutely need to retrieve the texture from the plane,

myTexture = plane.GetComponent ().material.mainTexture;

will return a texture2D if you declare “myTexture” as a texture2d variable since texture2D is a child class of texture.

Thanks !!!

This helped a lot !

Best
Alex