data.Items[key] -= 1
if data.Items[key] == 0:
var texture_to_check = load("res://assets/items/"+key+".png")
for button in get_tree().get_nodes_in_group("TextureButtons"):
if button.texture_normal == texture_to_check:
button.queue_free()
data.Items.erase(key)
It’s probably because when you execute “load” you’re actually creating a new reference for that image. You’re not just “loading the image”, you’re creating a resource in memory which is different than the image you have in your buttons. So that comparison if button.texture_normal == texture_to_check: will always return false.
Maybe find some other way to identify the buttons you have to free.
this makes since let me think on it for a bit kind of like if you make a file with class_name and then reference it in another file your creating a new version of said class file
You could compare the texure_normal.resource_path.
data.Items[key] -= 1
if data.Items[key] == 0:
var resource_path: String = "res://assets/items/"+key+".png"
for button in get_tree().get_nodes_in_group("TextureButtons"):
if button.texture_normal.resource_path == resource_path:
button.queue_free()
data.Items.erase(key)
You can set a better name for the group here too, If you use an instanced scene instead of making the button piece by piece you can set the group in the editor.