Load textures at runtime from outside the res file system

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Asolix

Is there a way in Godot 4 to load textures at runtime from outside the res:// file system without importing them into Godot beforehand?

I’ve already tried a lot, but somehow I can’t get any further and either get the error that resources have to be imported beforehand or, in the case of DDS textures, the error: Unrecognized or unsupported color layout in DDS.

Edit: External textures added for completeness can be loaded in both 3.5 and 4 as dds with the ResourceLoader. I had good results with the BC1/DXT1 format without mip maps.
For example, textures created under Godot 4 can be packed into a resource package with the PCKPacker at runtime, which can then be loaded at runtime and the dds textures contained therein can be used.

:bust_in_silhouette: Reply From: Gluon

Not really sure why you would want to load textures from outside the godot file system but in any case as far as I am aware it isnt possible. There is however a resource loader you can use to import the textures into the godot file system, details can be seen here

Thanks for the answer. Yes, this is exactly the part that gives me troubles with Godot 4. In the meantime I have tried it under 3.5, where images can be loaded without any problems. Only under Godot 4 it doesn’t seem to work.
I’ll play around with this a bit and maybe post it as a issue later.

Asolix | 2022-12-07 21:56

Ahh yes sorry i am in fact still using godot v3.5 as I dont want to port my whole game to 4 so it might be the case that there is some difference or error on godot 4.

Gluon | 2022-12-07 21:59

:bust_in_silhouette: Reply From: miremrie

I’ve had success with this code loading .png in Godot 4.0 stable.
There is an example in docs for ImageTexture

var image = Image.load_from_file(path)
var texture = ImageTexture.create_from_image(image)
brush.texture = texture

Here, path is an absolute path received by FileDialog picker, with file in the desktop folder, brush is a TextureRect
Tried on Windows 10. Seems to work in exported project also.

1 Like