I am sorry if this question is being asked because i missed something incredibly basic.
I am gettingKeyNotFoundException
with the error:
The given key was not present in the dictionary from Unity for a search for a Dictionary Key.
Example code is added below.
When I press GET DATA button on GUI it is working fine. But it is giving KeyNotFoundException
when I press GET DATA CAST button on GUI.
What I am missing? Any suggested changes that I need to make in code
I inserted data into Dict, sorry I missed that to post here Class
[System.Serializable]
public sealed class AnimName
{
public static readonly AnimName IDLE = new AnimName("IDLE");
public AnimName(string value)
{
Value = value;
}
public string Value { get; private set; }
}
Dict and Code:
Dictionary<AnimName, AnimData> KeyValueData = new Dictionary<AnimName, AnimData>();
//This is called once
Start(){
KeyValueData.Add(AnimName.IDLE, new AnimData(new Vector3(-0.09f, -0.02f, -0.25f), new Vector3(-41.866f, 386.781f, -524.68f), new Vector3(-0.028f, 0.027f, 0.13f), new Vector3(18.724f, 19.477f, -32.435f), 0.3f));
}
void OnGUI()
{
if (GUI.Button(new Rect(10, 10, 150, 100), "GET DATA"))
{
Debug.Log(KeyValueData [AnimName.IDLE]);
}
if (GUI.Button(new Rect(200, 10, 150, 100), "GET DATA CAST"))
{
AnimName a = new AnimName("IDLE");
Debug.Log(KeyValueData [a]);
}
}