Page 1 of 1

[SOLVED]KeyNotFoundException

Posted: Thu Feb 06, 2020 10:09 am
by mschoenhals
Hi,
I keep getting an error on one Quest Giver: KeyNotFoundException: the given key was not present in the dictionary. If I disable the Quest Giver it goes away.

I'm also getting a warning before it, probably related to a script that is trying to access the state of a quest: "GetQuestState(rescueEzmore): Could find a quest with ID 'rescueEzmore'

Here's the code that I wrote for checking quest state:

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PixelCrushers.QuestMachine;

public class CheckQuestState : MonoBehaviour
{
    [SerializeField] GameObject prefabOfNPC;

    void Start()
    {
        StartCoroutine(ActivateNPC(.5f));
    }

    IEnumerator ActivateNPC(float waitTime)
    {
        yield return new WaitForSeconds(waitTime);
        //static QuestState PixelCrushers.QuestMachine.QuestMachine.GetQuestState(string  questID, string  questerID = null);
        if (QuestMachine.GetQuestState("rescueEzmore") == QuestState.Successful)
        {
            print("my quest state is successful");
            prefabOfNPC.SetActive(true);
        }
    }
}
Is the warning related to the key error? Do I need to check if a quest state is null before I check if it's successful?

Thank you.

Re: KeyNotFoundException

Posted: Thu Feb 06, 2020 3:24 pm
by Tony Li
Hi,

They're probably related. Would you please click on the KeyNotFoundException in the Console window, press Ctrl+C to copy it to the clipboard, then paste it into a reply here?

Re: KeyNotFoundException

Posted: Fri Feb 07, 2020 8:09 am
by mschoenhals
Here you go:
KeyNotFoundException: The given key was not present in the dictionary.
System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at <df7127ba07dc446d9f5831a0ec7b1d63>:0)
RPG.Stats.Progression.GetStat (RPG.Stats.Stat stat, RPG.Stats.CharacterClass characterClass, System.Int32 level) (at Assets/Scripts/Stats/Progression.cs:18)
RPG.Stats.BaseStats.GetBaseStat (RPG.Stats.Stat stat) (at Assets/Scripts/Stats/BaseStats.cs:74)
RPG.Stats.BaseStats.GetStat (RPG.Stats.Stat stat) (at Assets/Scripts/Stats/BaseStats.cs:69)
RPG.Attributes.Health.GetInitialHealth () (at Assets/Scripts/Attributes/Health.cs:44)
GameDevTV.Utils.LazyValue`1[T].ForceInit () (at Assets/Asset Packs/GameDev.tv Assets/Scripts/Utils/LazyValue.cs:56)
RPG.Attributes.Health.Start () (at Assets/Scripts/Attributes/Health.cs:49)

Re: KeyNotFoundException

Posted: Fri Feb 07, 2020 8:55 am
by Tony Li
What is line 18 of Progression.cs?

Re: KeyNotFoundException

Posted: Sat Feb 08, 2020 11:34 am
by mschoenhals
Hi Tony,
My apologies - the error was related to the game's experience progression system. Not sure where the change happened as I hadn't played around with it in a while but I found the error.

Thanks very much for your help.
Mike