Load a TextureRect texture into the code

Godot Version

Godot Engine v4.3.stable.mono.official.77dcf97d8 - https://godotengine.org

Question

I’m trying to display a screenshot of the game that was previously made in another scene, but godot doesn’t seem to find it, even though the path is correct and the screenshot exists. I even check it beforehand with “FileAccess”.
here’s the error message:

E 0:00:01:0396   home.gd:29 @ _ready(): Resource file not found: user://slot1/slot1.png (expected type: )
  <C++ Error>    Condition "!file_check->file_exists(p_path)" is true. Returning: Ref<Resource>()
  <C++ Source>   core/io/resource_loader.cpp:288 @ _load()
  <Stack Trace>  home.gd:29 @ _ready()

and I tested all these methods to load the texture:

§TextureRect.set_texture(ImageTexture.create_from_image(load(path)))

§TextureRect.set_texture(load(path)

§TextureRect.texture = load(path)


load only works on packaged resources, that will essentially only be “res://” paths

You need to use Image.load_from_file(path), then you can use ImageTexture.create_from_image on it’s result.

1 Like