Ok, if I get it right then you use a Vector2 as Key for erase?
Actually, I never used anything other than strings as keys in dictionaries so my experience here is a bit limited.
But if that is true, then you basically use a vectoy consisting of 2 float values for comparison (in erase). And as you might know, comparing floats with == is risky. Normally, you compare floats like this: abs(float2-float1) < margin_of_error
. Where marginoferror is a low value depending on your typical number range (i.e. 0.0001). With Vector2, it may be something like (Vector2-Vector1).length() < margin_of_error
.
#1:
You can check, if this "comparison" problem is actually the problem here. Simply output the result of dictionary.has(key) before using erase and you'll know if there's actually a match to erase.
#2:
You could use a key which is comparable. I.e. use a string-representation with rounded values. Naturally, this uses additional CPU.