0 votes

Im trying to make it so it will pull an image of your choice from the user:// folder, it then makes it a res:// image and sets it as an imagetexture to show up on a panel node to display it to you in-game. Ive tried as much as I could bit it always ends in an error. Last error says invalid set index 'texture' (on base: 'ImageTexture') with type: 'image'.
The local_data dictionary is the path.

match local_data["files"][id][id]["file_type"]:
    "png":
        var image = Image.new()
        var preview_tex = ImageTexture.new()
        image.load(game.local_data["files"][id][id]["image"])
        var path_split = game.local_data["files"][id][id]["image"].split("//")
        var res_path = "res://" + str(path_split[1])

        preview_tex.create_from_image(image)
        preview_tex.texture = image
        image_preview.add_theme_stylebox_override("panel",preview_tex)
        no_prev_label.hide()
Godot version 4.0-stable
in Engine by (20 points)

1 Answer

0 votes

Keep in mind, once a project is exported, you can't write to res://.
Why do you need an image in user:// to be in res://? Also, you don't even use your res_path variable.

ImageTexture doesn't have a texture member (third to last line), you have to use the set_image() method.

by (1,607 points)

I was tinkering with it which is why there are unused variables in it. res_path did have a use but was removed because it kept erroring. My goal is to make it so you can select an image from user:// and to apply it as the wallpaper or profile picture.
I know how to do the imagetexture part, I've done it with the wallpaper functionality, but the image importing is quite a challenge.

How do you import an image from user:// to use it in the game then? (with code)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.