Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question Why can (byte[])Texture2D.GetTextureRawData() acess unreadable texture's data?

Discussion in 'Documentation' started by lang_dye, Feb 26, 2021.

  1. lang_dye

    lang_dye

    Joined:
    Aug 9, 2019
    Posts:
    2
    Hi everyone! In the document, we all know scripts can't acess unreadable texture's data, but I found that (byte[])Texture2D.GetTextureRawData() this api still can acess the data and the return data is correct, is it something wrong?
    Code (CSharp):
    1. var mesh = GetComponent<MeshRenderer>();
    2. Material mat = mesh.sharedMaterial;
    3. var tex = (Texture2D)mat.GetTexture("_MainTex");
    4. var data = tex.GetRawTextureData();
    this is my test code, and _MainTex's "Read/Write Enabled" is false. My unity version is 2019.4 LTS.
    so is it a bug of unity document? or is this api special ?