So, I am getting the following error (that I have not yet run into) when iterating over a Dictionary in my code. It’s a simple piece of code that iterates through the dictionary and resets the player scores inside it. Here’s there code
void resetScore () {
foreach (KeyValuePair<string, int> pair in points) {
points[pair.Key] = 0;
}
}
And here is the error
InvalidOperationException: out of sync
System.Collections.Generic.Dictionary`2+Enumerator[System.String,System.Int32].VerifyState () (at /Applications/buildAgent/work/3df08680c6f85295/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:912)
System.Collections.Generic.Dictionary`2+Enumerator[System.String,System.Int32].MoveNext () (at /Applications/buildAgent/work/3df08680c6f85295/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:835)
gameManager.resetScore () (at Assets/code/gameManager.cs:85)
gameManager.turnRound () (at Assets/code/gameManager.cs:44)
gameManager.scoreUpdate (System.String scoringPlayer, Int32 scoreValue) (at Assets/code/gameManager.cs:80)
goal.OnTriggerEnter (UnityEngine.Collider obj) (at Assets/code/goal.cs:10)
I’m not entirely sure what this error means or how to go about dealing with it. Any help is most appreciated.