Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

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 ?