[SOLVED] Loading resources from "user://"

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

Hello,

I’m trying to load resources (e.g. images) from “user://” path in GDScript and I got this error:

ERROR: _load_data: Condition ' !f ' is true. returned: ERR_CANT_OPEN
   At: scene/resources/texture.cpp:424
ERROR: Failed loading resource: res://.import/quest_background.png-eaaa035fe9ed74e4d9dc622678e6196d.stex
   At: core/io/resource_loader.cpp:186
ERROR: Failed loading resource: user://quests/q1/quest_background.png
   At: core/io/resource_loader.cpp:186

Here is my code example:

var image = load("user://quests/q1/quest_background.png").duplicate()

How can I achieve this?

Best regards,
Radu

unless you placed an image on the user:// then the image is suppose to be in the res:// folder(if you placed it through the editor)

rustyStriker | 2018-06-30 11:25

:bust_in_silhouette: Reply From: radubolovan

This can be done by manually creating the image:

func crate_sprite(path):
    var img = Image.new()
    var err = img.load(path)
    if(err != 0):
        print("error loading the image: " + path)
        return null
   var img_tex = ImageTexture.new()
   img_tex.create_from_image(img)

   var sprite = Sprite.new()
   sprite.texture = img_tex

   return sprite