Invalid set index 'texure' (on base: 'TextureRect') with value of type 'CompressedTexture2D'

Godot Version

godot4.0

Question

I’m trying to implement a function that allows a certain texurerect panel to change sprite given by a command. here is my code:

func _change_avatar(avatar: String, position = "mid"):
	var start_location = "res://artResource/"
	var avatar_at = _helper_search_file(start_location, avatar)
	if position == "left":
		$background/left/character.texture = ResourceLoader.load(avatar_at)
	elif position == "right":
		$background/right/character.texture = ResourceLoader.load(avatar_at)
	elif position == "mid":
		$background/mid/character.texture = ResourceLoader.load(avatar_at)

the _helper_search_file returns the location of the file I want to find and works perfectly.
Now, ik the code above is kind of dum since my node has layout as such:
image

thus the entire if statement can be changed as:

%background.find_child(position).find_child("character").texure = ResourceLoader.load(avatar_at)

However, my simplified code give me an error called:
"Invalid set index ‘texure’ (on base: ‘TextureRect’) with value of type ‘CompressedTexture2D’. "
which means while the node is find, the texure somehow won’t fit in.

I am very confused right now, can anyone help me out?

you have a typo in “.texure”, its supposed to be “.texture”

1 Like

lmao its such a simple mistake :joy:

1 Like

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