Godot Version
4.7
Question
At the moment, I have an array that is storing useful info for my game:
class ItemInfo:
var source:NodePath
var amount:int
var used:bool
...
var item_list:Array[ItemInfo]
I’d like to add a reverse lookup to find ItemInfo based on the source parameter. That is, something like:
# Return the ItemInfo in item_list where 'ItemInfo.source'
# references the same node as 'path'
func get_item_info(path:NodePath)->ItemInfo:
I was thinking of using a Dictionary[NodePath, ItemInfo] for this, but more than one NodePath can point to the same node, so I don’t have a guarantee that the NodePath I’m passing to get_item_info will be the same one that I used as the key to my Dictionary. What would be a good way to look up my ItemInfo given a NodePath?