I’m trying to set a TextureRect and a sprite’s texture from an image that is at the external storage.
On PC, it works fine.
However, on android the textures just won’t show up and the sprites/texturerects are completely invisible.
One important note, is that sprites that I have already made before exporting to .apk which have textures based on images from the res:// folder do seem to show up and load.
How can I solve this issue?
Edit:
I’ve checked that post and it doesn’t seem to be relevant to my problem:
I’ve checked that post as well, and I can’t find the option to switch to GLES2:
Edit2: Another interesting note is that when I try to output the texture’s size to a text label it shows nothing, hinting that the sprite/texturerect’s texture is null. On PC there is texture and size is shown in the text label.
try to save it as a raw Image type, problem will be you dont drag and drop this kind of image import type to scene, it will bloat your scene size.
here is the snippet how to load it from code:
var raw_image=load("res://assets/images/raw_image.jpg")
var raw_image_texture= ImageTexture.create_from_image(raw_image_texture)
texture_rect.texture=raw_image_texture
what i meant by raw Image type:
if you do the above, you should be able to load image from res://
the explanation for this why this work, why the normal Texture2D doesnt work is because Texture2D in res:// is converted to compressed mode and saved in .import folder. the original Texture2D wont get exported on builds
Hi, thank you for answering.
I’ve tried to use the function create_from_image() on PC (and I’ve loaded a image from res:// and also tried an image from outside the res://), and the function returns null.
What could be the cause?
Edit: Turns out I should’ve used Image.load_from_file() in order to load the file as an Image.
Now it works on the exported version! Thank you, solved.