- Home /
The Given Key cannot be found in the Dictionary and I have no idea why. Worked perfectly before.
I am getting the error of:
KeyNotFoundException: The given key was not present in the dictionary.
System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at <437ba245d8404784b9fbab9b439ac908>:0)
numberlist.Update () (at Assets/Scripts/numberlist.cs:87)
I've been looking up information on this error but I don't know how the other questions can apply to my code. The weird thing is, this code was working perfectly and then one day I open up Unity and it's no longer working. I don't think I changed anything.
The code for this is below. I updated Unity recently, maybe there was a change in there? I'm so confused. If anyone can help, thank you so so so so so so so so so much! ^u^
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class numberlist : MonoBehaviour
{
public static Transform THESEARETHECOORDINATESOFSLOTONE;
public static Transform THESEARETHECOORDINATESOFSLOTTWO;
public static Transform THESEARETHECOORDINATESOFSLOTTHREE;
public static float THISISTHELITERALSLOTONE;
public static float THISISTHELITERALSLOTTWO;
public static float THISISTHELITERALSLOTTHREE;
public GameObject CanvasObject;
//public GameObject Script“Character Saying This” Memory of “ Character Remembering It ” “Clue Info”.
public GameObject ScriptJONASMemoryofTESTPeterSelfish;
public GameObject ScriptJONASCafeteriaBleach;
public GameObject ScriptJONASSawAlice;
public GameObject ScriptJONASArgueSylvia;
public GameObject ScriptJONASJungSmoke;
public static List<float> THISISTHEACTUALLIST = new List<float>() { 0, 0, 0 };
public static Dictionary<float, GameObject> ObjectsTable = new Dictionary<float, GameObject>();
//TIP : DoNotDestroyOnLoad(Object object) on anything if you wanna save it between scenes.
void Start()
{
THESEARETHECOORDINATESOFSLOTONE = movetheui.MovingSlotOneCoordinates;
THESEARETHECOORDINATESOFSLOTTWO = movetheui.MovingSlotTwoCoordinates;
THESEARETHECOORDINATESOFSLOTTHREE = movetheui.MovingSlotThreeCoordinates;
CanvasObject = GameObject.Find("Clue Holder");
DontDestroyOnLoad(CanvasObject);
//Script“Character Saying This” Memory of “ Character Remembering It ” “Clue Info”. = GameObject.Find(“Character Saying This” Memory of “ Character Remembering It ” “Clue Info”.)
//Script“Character Saying This” Memory of “ Character Remembering It ” “Clue Info”.SetActive(false);
ScriptJONASMemoryofTESTPeterSelfish = GameObject.Find("JONAS Memory of TEST Peter Selfish");
ScriptJONASCafeteriaBleach = GameObject.Find("JONAS Cafeteria Bleach");
ScriptJONASSawAlice = GameObject.Find("JONAS Alice Saw");
ScriptJONASArgueSylvia = GameObject.Find("JONAS Sylvia Argue");
ScriptJONASJungSmoke = GameObject.Find("JONAS Jung Smoke");
//Object table
//ObjectsTable.Add(Number, Script“Character Saying This” Memory of “ Character Remembering It ” “Clue Info”.);
ObjectsTable.Add(1, ScriptJONASMemoryofTESTPeterSelfish);
ObjectsTable.Add(2, ScriptJONASCafeteriaBleach);
ObjectsTable.Add(3, ScriptJONASSawAlice);
ObjectsTable.Add(4, ScriptJONASArgueSylvia);
ObjectsTable.Add(5, ScriptJONASJungSmoke);
}
// Update is called once per frame
void Update()
{
THESEARETHECOORDINATESOFSLOTONE = movetheui.MovingSlotOneCoordinates;
THESEARETHECOORDINATESOFSLOTTWO = movetheui.MovingSlotTwoCoordinates;
THESEARETHECOORDINATESOFSLOTTHREE = movetheui.MovingSlotThreeCoordinates;
float slot1id = THISISTHEACTUALLIST[0];
float slot2id = THISISTHEACTUALLIST[1];
float slot3id = THISISTHEACTUALLIST[2];
ObjectsTable[slot1id].SetActive(true);
ObjectsTable[slot1id].transform.position = THESEARETHECOORDINATESOFSLOTONE.position;
ObjectsTable[slot2id].SetActive(true);
ObjectsTable[slot2id].transform.position = THESEARETHECOORDINATESOFSLOTTWO.position;
ObjectsTable[slot3id].SetActive(true);
ObjectsTable[slot3id].transform.position = THESEARETHECOORDINATESOFSLOTTHREE.position;
}
}
Firstly, your casing is all over the place. There are language conventions and you should ad hear to them because it means its easier to understand your code because it will look like all other well written code and most importantly the .NET framework.
Right now thats said and done.
What is it that you are trying to do?