Godot: Loading resources from user://

Created on 22 Apr 2018  路  4Comments  路  Source: godotengine/godot

An error from https://github.com/godotengine/godot/issues/2319 is occurring in Godot 3.0.2. This error does not occur when loading a tscn file.

ERROR: _load: No loader found for resource: user://icon.png
At: core/io/resource_loader.cpp:186.

archived

Most helpful comment

func load_jpg(file):

    var jpg_file = File.new()

    jpg_file.open(file, File.READ)

    var bytes = jpg_file.get_buffer(jpg_file.get_len())

    var img = Image.new()

    var data = img.load_jpg_from_buffer(bytes)

    var imgtex = ImageTexture.new()

    imgtex.create_from_image(img)

    jpg_file.close()

    return imgtex

```

func load_png(file):

var png_file = File.new()

png_file.open(file, File.READ)

var bytes = png_file.get_buffer(png_file.get_len())

var img = Image.new()

var data = img.load_png_from_buffer(bytes)

var imgtex = ImageTexture.new()

imgtex.create_from_image(img)

png_file.close()

return imgtex

```

File is the path in this case, like

var img = "user://image.jpg"
texturebutton.normal = load_jpg(img)

All 4 comments

I may be wrong here but isn't the problem here that loading an image like that when it's not imported by the editor doesn't work? The resource loader tries to load SteamTextures which don't exist for user://. You could try using ImageTexture I believe.

func load_jpg(file):

    var jpg_file = File.new()

    jpg_file.open(file, File.READ)

    var bytes = jpg_file.get_buffer(jpg_file.get_len())

    var img = Image.new()

    var data = img.load_jpg_from_buffer(bytes)

    var imgtex = ImageTexture.new()

    imgtex.create_from_image(img)

    jpg_file.close()

    return imgtex

```

func load_png(file):

var png_file = File.new()

png_file.open(file, File.READ)

var bytes = png_file.get_buffer(png_file.get_len())

var img = Image.new()

var data = img.load_png_from_buffer(bytes)

var imgtex = ImageTexture.new()

imgtex.create_from_image(img)

png_file.close()

return imgtex

```

File is the path in this case, like

var img = "user://image.jpg"
texturebutton.normal = load_jpg(img)

duplicate: #17748 (#17848 is the new issue)

Yes, looks like a duplicate of #17848 indeed. Closing.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RebelliousX picture RebelliousX  路  3Comments

timoschwarzer picture timoschwarzer  路  3Comments

mefihl picture mefihl  路  3Comments

Spooner picture Spooner  路  3Comments

bojidar-bg picture bojidar-bg  路  3Comments