Loaded image as resource file, this will not work on export

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

I’m making an application that randomly generates a set of characters for a game and then displays them in UI. I have an image for each character saved in res://, and the needed image (determined after randomization) is found in the file system and set as the texture for a TextureRect via code. This is an example of what I’m doing:

func add_texture(imagePath : String, objectPath : String):
  var image = Image.new()
  var texture = ImageTexture.new()

  get_node(objectPath).texture = texture

This produces the error in the title. Is there a way to either fix the code or try something else that doesn’t produce the error? I’ve been trying to troubleshoot this for about two hours and haven’t found anything that fixes my problem.

:bust_in_silhouette: Reply From: Inces

You have overcomplicated this.
If I understand Your vision correctly, all You need is one String with chosen name. Choose randomly form array of strings and input resulting randomized_name into :
var randomimage = load(“res://” + randomized_name + “.png”)
Colorrect.texture = randomimage

Reason for error was that You called other node to load anything. Load or preload can only be executed “personally” by nodes

This worked perfectly, thank you :slight_smile: I feel silly for making it so complicated initially though lol

EliTheBeeli | 2021-12-07 18:18