Can I use NodePath as a key in a Dictionary to find nodes?

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?

You can make/use sorted Array, depends how many objects you planing, for start just use Array

Why not just use Dictionary[Node, ItemInfo]?

Do you mean by the path being relative? I.e. foo/bar/baz being the same as bar/baz from foo? You can make them absolute and that way they’ll be unique