Hi all,
I am trying to load a png image with transparency at runtime via;
UnityWebRequestTexture.GetTexture(“file://” + path)
This works fine on windows, in the editor, but on Android (I have tried two separate devices) the transparent areas show as black. I am showing on screen in a UI Image. I have also tried opening the same image in another android app and it recognizes the transparency correctly.
The image in question was made in Paint.NET using it’s default settings for pngs and can be downloaded here.
Any suggestions how I can fix this?
6.3 LTS is the version that is Recommended for production for now. Did you try it?
If you need 6.4 for some reason, please submit a bug report via Unity Bug Reporter as well. Also, attach the internal number that you will receive via Email after submitting. Only a post with such a number makes sense here on Discussions.
Thanks for the reply @makaka-org. I was working in version 6000.0.59f2 up till today. I encountered this issue and tried upgrading to see if that resolved it. I went with 6.4 only because that is what the hub marks as recommended;
I can try 6.3 as well but given that the issue is present in 6.0 and 6.4 I don’t have much hope.
The UI Image isn’t using a custom shader?
You could try rendering it as a sprite to see if this also appears with black borders. And try with various other PNGs from different sources.
It might be some PNG compatibility problem, I used to have troubles loading Inkscape created PNGs on iOS at all. The solution was to open the PNG and save it in practically any other image editing/viewing program.
No custom shader, it’s just what you get when you create a UI Image via GameObject->UI Canvas->Image. I will try a sprite shortly. I tried resaving the image as a png from both GIMP and mspaint and it made no difference.
For starters, create readable texture and sample the pixels where you expect transparency. What is the alpha value?
Sorry for the delay @aurimasc. On windows, where the image behaves correctly I get;
Color : RGBA(0.000, 0.000, 0.000, 0.000)
For pixel (0, 0), whereas on Android I get;
Color : RGBA(0.000, 0.000, 0.000, 1.000)
Any suggestions?
@makaka-org I have also managed to test this on 6.3 and again, it makes no difference. This is what I get running in the editor:
And this is what I get on Android
UnityWebRequestTexture.GetTexture can take this struct as parameter: Unity - Scripting API: DownloadedTextureParams
Perhaps playing around with these settings (like mipmaps) can help. If not, then it sounds like a bug to me.
I reported this to Unity support that they pointed out that the issue is with how I am getting the file path to the image. I am using a file picker that allows Android to resize the image, which apparently has a habit of converting to jpeg which strips the transparency. The solution, in my case, was to just set the file picker to never resize the image.