Godot Version
4.3
Question
So I created an inventory scene with a gridcontainer filled with TextureRects. Works great.
But when I make a scene out of TextureRect and instance that in the Inventory scene, now everytime I change one of them, they all become the same inventory item. Here’s the code for the ItemNode
extends TextureRect
var id: int = 0
var item_name: String = ""
var item_region: Vector2 = Vector2(0,0)
var item_region_dict = {
"apple": Vector2(512,288), "sword": Vector2(544,448), "armor": Vector2(554,336),
"cheese": Vector2(576,288), "helmet": Vector2(544,320), "shield": Vector2(528,352),
"bow": Vector2(656,368), "staff": Vector2(608,384),
}
func define(new_id, new_name):
id = new_id
item_name = new_name
self.texture.region = Rect2(item_region_dict[item_name], Vector2(16, 16))
In my inventory scene, if I call $Slot1.define(1, “apple”) and then $Slot2.define(2, “sword”), all the slots become swords.
I’ve looked online and some people say you would make the instanced scene local, but that doesn’t help. Others say you should check editable children, but that doesn’t work either.
I’m very confused. I’ve make a small monster game before and every time I instanced a monster, they were unique and all the monsters didn’t become the most recently instanced monster.