Triggering re-import assets?

Godot Version

4.2.2

Question

How can I trigger re-import assets?
This code would work fine if the exact same texture wasn’t loading all the time. Unless I open the editor window, it just won’t load properly, so I’m looking for either a fix for this or an alternative code that enables me to load the new texture

var texture = ResourceLoader.load(ruta) if ResourceLoader.exists(ruta) else default
sprite.texture = texture

the file was saved before by

func screenshot():
var captura = get_viewport().get_texture().get_image()
captura.save_png(“res://screenshot.png”)

I made sure that all routes and references are fine

The resource you loaded was cached by default. Try use ResourceLoader.load() to specify the cache_mode to CACHE_MODE_REPLACE.

1 Like

I tried with

var texture = ResourceLoader.load(ruta, “”, 2) if ResourceLoader.exists(ruta) else default
It didn’t work, I also tried with some type_hint such as Image or Texture but nothing worked, maybe it has something to do with ProjectSettings.editor/export/convert_text_resources_to_binary
I am going to check it

res:// is read-only on exported projects so you won’t be able to save the screenshot that way.

You’ll need to use user:// for that.

You can check this documentation page Runtime file loading and saving — Godot Engine (stable) documentation in English to know how to load files like pngs at runtime.

1 Like

I finally solved it, but it works fine either using user:// or res:// (anyways I decided to use user://)
I just set at top of the code
var image = Image.load_from_file(“user://screenshot.png”)
then I swapped the code to:

	var texture = ImageTexture.create_from_image(image) if image else default
	background.texture = texture

I just copied it from the docs. Files can be stored in res and also saved, but I think that
Image.load_from_file("user://screenshot.png")
is the line that fixed everything, thank you so much for all the help

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.