Using a Vector2 as a key doesn't find anything, despite values being identical?

Hello. I am currently having troubles with using Vector2s as keys for a dictionary.
Currently, I set a Vector2 as a key for a value (the value being another dictionary). When I attempt to get the value using an identical Vector2, it doesn’t return anything.

    local gridLocation = grid:GetAttribute("GridPosition")
	self.CurrentGrid = gridLocation
	local gridData = SessionData.ModifiedGrids[gridLocation]
	-- If the grid is not a default one
	if gridData then
		-- We load the information for the grid here
		print("Grid data found! Loading grid")
		clearWindow()
		createProperty("GridType", gridData.GridType, GameEnum.GridProperties.GridType)
	else
		-- We load the default possible properties for a grid here
		print("No grid data found, loading default")
		clearWindow()
		createProperty("GridType", GameEnum.GridProperties.GridType.None, GameEnum.GridProperties.GridType)
	end

The code above, even when the SessionData.ModifiedGrids contains a Vector2, will not return the value when I use an identical key.
So, does anyone know a solution/workaround?

Vector2 is a userdata, so every new Vector2 is a different Vector2 (basically a different address).

You can use an array or string keys instead.

1 Like