- Home /
KeyNotFoundException:The given key was not present in the dictionary.
So I was just kind of practicing my skills, but I ran into a problem that I couldn't find the answer to ( it may be a simple fix). It has to do with Input.GetKeyDown. So the error I get is this. KeyNotFoundException:The given key was not present in the dictionary. If you find the problem I will very grateful to you. Thanks! Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PortalMove : MonoBehaviour {
public Animator anim;
// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
bool move = Input.GetButtonDown("Jump");
anim.SetBool ("Stop", move);
}
}
(BTW, I am pretty sure it is line 11 (the bool line) that is the problem)
Are you sure your animator has a Stop
parameter? (Which is different from a Stop
state). $$anonymous$$ake sure you haven't mispelled the parameter name (example stop
!= Stop
)
Answer by Injec · Oct 12, 2017 at 02:04 PM
Hey, it means, that the key "Jump" of the dictionary doesn't exist. Have a look at your InputManager and look, if the key exists in there.
The error would be the following if the problem came from the Input$$anonymous$$anager :
ArgumentException: Input Button Jump is not setup. To change the input settings use: Edit -> Project Settings -> Input
Oh yeah, right. Then it is probable the key of the animator. So is there a key named "Stop" in your animator? Do you maybe get the wrong Animator? or is "Stop" written in small letters in you animator?