Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

SetPixel(s) > Apply on Texture2D with no transparency in its RW enabled base texture has black alpha

Discussion in 'Editor & General Support' started by MD_Reptile, Jan 15, 2019.

  1. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    I found an unusual bug in Unity 2018.2.16f1.

    If you use a fully opaque texture as the texture of a sprite renderer, then you modify that texture with SetPixel(s) and use Apply(false) on the texture to send changes to the GPU - unity will draw black pixels where you place transparent (alpha 0) pixels in the texture. Here is an example:



    In the image above you can see the bottom left "tile" of the image has transparency, while all the others do not. Thats because the default texture assigned to the bottom left has a texture thats got transparency in it in the file. All the others have a solid white texture with no transparency. All the textures have the same settings and allow for transparency, full rect sprites. When entering play mode, I generate the "islands" you see there, and there is expected to be transparency between those "islands" of opaque pixels, but for some reason it will only work if the base texture has alpha.

    I haven't filed a bug report and would like to see if anybody else has ran into this, or if its possible I configured something wrong in my project - either way I've found a workaround by just using a base texture with some alpha pixels in it.

    If anybody can confirm with 2018.x or 2019.x unity, and you see the same issue, I'll go ahead and create a bug report.

    The texture I used that works as expected and maintains transparency:


    EDIT: The color of the transparent pixels may not be black, unless you set the RGB values to 0 as well as the alpha - otherwise the black pixels would be a different color.
     
    Last edited: Jan 15, 2019