[SOLVED]KeyNotFoundException

Announcements, support questions, and discussion for Quest Machine.
Post Reply
mschoenhals
Posts: 118
Joined: Thu Dec 19, 2019 7:38 am

[SOLVED]KeyNotFoundException

Post 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.
Last edited by mschoenhals on Sat Feb 08, 2020 11:34 am, edited 1 time in total.
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: KeyNotFoundException

Post 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?
mschoenhals
Posts: 118
Joined: Thu Dec 19, 2019 7:38 am

Re: KeyNotFoundException

Post 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)
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: KeyNotFoundException

Post by Tony Li »

What is line 18 of Progression.cs?
mschoenhals
Posts: 118
Joined: Thu Dec 19, 2019 7:38 am

Re: KeyNotFoundException

Post 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
Post Reply