Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | pbij |
I have a set of code in an autoload script whose purpose is to update the visuals of my inventory slots.
Problem is that when I change scenes the node’s path changes and this code no longer works.
func _update_slot_visual(slotIndex, item_name, new_quantity):
var slot = get_tree().root.get_node("/root/Home/UserInterfaceGroup/Inventory/InventoryContainer/Slot" + str(slotIndex))
if slot.item != null:
slot.item._set_item(item_name, new_quantity)
else:
slot._initialize_item(item_name, new_quantity)
The path /root/Home/UserInterfaceGroup/Inventory/InventoryContainer/Slot
changes to /root/Level1/UserInterfaceGroup/Inventory/InventoryContainer/Slot
when the scene changes.
I was hoping that changing the line to this would work, but it just comes up null:
var slot = get_tree().root.find_node("/root/*/UserInterfaceGroup/Inventory/InventoryContainer/Slot" + str(slotIndex))