Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by PredatorProductions · Jan 19, 2017 at 09:41 AM · errordictionaryachievement

KeyNotFoundException: The given key was not present in the dictionary.

i have no Idea what is going on. It was working perfectly fine then I added a few more achievements and now i get the error. Please help I've spent hours on this problem and I'm really not sure what to do at this point.

It only lets me instantiate the first 11 on load. Also It starts with the Achievement Menu active, rather than waiting for input "I" before opening.

Thank you all for your time!

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement;

public class AchevemntManager : MonoBehaviour {

 public GameObject achievmentPrefab;

 public GameObject achivementMenu;

 public Sprite[] sprites;

 public GameObject visualAchievment;

 public Dictionary<string, Achevment> achivements = new Dictionary<string, Achevment> ();

 public Sprite unlockedSprite;

 private int fadeTime = 2;

 private static AchevemntManager instance;

 public static AchevemntManager Instance

 {
     get 
     { 
         if (instance == null) 
         {
             instance = GameObject.FindObjectOfType<AchevemntManager> ();
         }
         return AchevemntManager.instance; 
     } 

 }


 // Use this for initialization
 void Start () {

     PlayerPrefs.DeleteAll ();

     //achivements.Add("FirstBloodAchevment",new Achevment("First Blood", "Made your first kill huh? How'd it feel?" this));

     CreateAchievment ("General","Sympathizer","Talk to a monster...They can't be that bad, right?",0);

     CreateAchievment ("General","Poor Alex","See Alex at her worst.",1);

     CreateAchievment ("General","Poor, Poor Alex","See Alex at her worst, twice.",2);

     CreateAchievment ("General","Cat Whisperer","Talk to a cat you didn't have to talk to.",3);


     CreateAchievment ("General","The Hostel","Defeat the Great Beast in the Hostel Halls. Did you run or did you fight?",4);

     CreateAchievment ("General","Dream Walker","Defeat the Beast that lives in your Dreams. Did you run or fight?",5);

     CreateAchievment ("General","Hell Spawn","Defeat the Beast that stirs in the depths. Did you run or fight?",6);

     CreateAchievment ("General","Smoke and Ash","Discover the Good Ending.",7);

     CreateAchievment ("General","Last Rites","Discover the Bad Ending.",8);

     CreateAchievment ("General","Five More Minutes","Discover a Passive Ending.",9);

     CreateAchievment ("General","The Sad Truth","Discover the all of the endings.",10, new string[]{"Smoke and Ash","Last Rites","The Broken"});

     CreateAchievment ("General","The Elder","Follow the Candle.",11);

     CreateAchievment ("General","The Beast","Follow the Cane.",12);

     CreateAchievment ("General","The Sacrifice","Follow the Blade.",13);

     CreateAchievment ("General","The Abused","Follow the Phone.",14);

     CreateAchievment ("General", "The Butterfly", "Follow the Cuff.", 15);

     CreateAchievment ("General","The Punished","Follow the Car.",16);

     CreateAchievment ("General","The Whole Truth","Discover the whole story.",17, new string[]{"The Elder","The Beast","The Sacrifice","The Abused","The Butterfly","The Punished","The Sad Truth","The Broken"});


     CreateAchievment ("General","The Fool","Put ??? to Sleep.",18);

     CreateAchievment ("General","The Playground","Put Marchosias to Sleep.",19);

     CreateAchievment ("General","The Failure","Put Lucas to Sleep.",20);

     CreateAchievment ("General","The Tortured","Put Alex to Sleep.",21);

     CreateAchievment ("General","The Justifier","Put Amy to Sleep.",22);

     CreateAchievment ("General","The Wrathful","Put Daudaz to Sleep.",23);

     CreateAchievment ("General","The Broken","Discover all Passive Endings.",24, new string[]{"The Fool","The Playground","The Failure","The Tortured","The Justifier","The Wrathful"});

     CreateAchievment ("General","First Step","The Longest Journey Starts With a Single Step.",25);




     achivementMenu.SetActive (false);
 }


 
 // Update is called once per frame
 void Update ()
 {
     if (Input.GetKeyDown (KeyCode.I)) 
     {
         achivementMenu.SetActive (!achivementMenu.activeSelf);
     }
 
     if (Input.GetKeyDown (KeyCode.D)) 
     {
         EarnAchivment("First Step");
     }

     /*if (Input.GetKeyDown (KeyCode.O)) 
     {
         EarnAchivment("Sympathizer");
     }

     if (Input.GetKeyDown (KeyCode.P)) 
     {
         EarnAchivment("Poor Alex");
     }

     if (Input.GetKeyDown (KeyCode.L)) 
     {
         EarnAchivment("Poor, Poor Alex");
     }

     if (Input.GetKeyDown (KeyCode.L)) 
     {
         EarnAchivment("Temple Runner");
     }

     if (Input.GetKeyDown (KeyCode.L)) 
     {
         EarnAchivment("The Hostel");
     }

     if (Input.GetKeyDown (KeyCode.L)) 
     {
         EarnAchivment("Dream Walker");
     }

     if (Input.GetKeyDown (KeyCode.L)) 
     {
         EarnAchivment("Hell Spawn");
     }

     if (Input.GetKeyDown (KeyCode.L)) 
     {
         EarnAchivment("Smoke and Ash");
     }


     if (Input.GetKeyDown (KeyCode.L)) 
     {
         EarnAchivment("Last Rites");
     }

     if (Input.GetKeyDown (KeyCode.L)) 
     {
         EarnAchivment("Five More Minutes");
     }

     if (Input.GetKeyDown (KeyCode.L)) 
     {
         EarnAchivment("The Sad Truth");
     }

     if (Input.GetKeyDown (KeyCode.L)) 
     {
         EarnAchivment("The Elder");
     }

     if (Input.GetKeyDown (KeyCode.L)) 
     {
         EarnAchivment("The Elder");
     }

     if (Input.GetKeyDown (KeyCode.L)) 
     {
         EarnAchivment("The Beast");
     }

     if (Input.GetKeyDown (KeyCode.L)) 
     {
         EarnAchivment("The Sacrifice");
     }

     if (Input.GetKeyDown (KeyCode.L)) 
     {
         EarnAchivment("The Abused");
     }

     if (Input.GetKeyDown (KeyCode.L)) 
     {
         EarnAchivment("The Butterfly");
     }

     if (Input.GetKeyDown (KeyCode.L)) 
     {
         EarnAchivment("The Punished");
     }

     if (Input.GetKeyDown (KeyCode.L)) 
     {
         EarnAchivment("The Whole Truth");
     }*/

 }

 public void EarnAchivment(string title)
 {
     if (achivements [title].earnAchievment ()) 
     {
         GameObject achievment = (GameObject)Instantiate (visualAchievment);
         SetAchievmentInfo("EarnCanvis", achievment, title);
         StartCoroutine (FadeAchivement (achievment));
     }
 }

 public IEnumerator HideAchivement(GameObject achievment)
 {
     yield return new WaitForSeconds (3);
     Destroy (achievment);
 }

 public void CreateAchievment (string parent, string title, string description, int spriteIndex, string[] dependecies = null)

 {
     GameObject achievment = (GameObject)Instantiate (achievmentPrefab);

     Achevment newAchevment = new Achevment (name, description, spriteIndex, achievment);

     achivements.Add (title, newAchevment);

     SetAchievmentInfo (parent, achievment, title);

     if (dependecies != null)

     {
         foreach (string achivementTitle in dependecies)
         {
             Achevment dependency = achivements [achivementTitle];
             dependency.Child = title;
             newAchevment.AddDependency (achivements [achivementTitle]);


         }
     }
 }

 public void SetAchievmentInfo(string parent, GameObject achievent,string title)

 {
     achievent.transform.SetParent(GameObject.Find(parent).transform);
     achievent.transform.localScale = new Vector3 (1, 1, 1);
     achievent.transform.GetChild(0).GetComponent<Text>().text = title;
     achievent.transform.GetChild(1).GetComponent<Text>().text = achivements[title].Description;
     achievent.transform.GetChild(2).GetComponent<Image>().sprite = sprites[achivements[title].SpriteIndex];
 }

 private IEnumerator FadeAchivement(GameObject achievent)
 {
     CanvasGroup canvasGroup = achievent.GetComponent<CanvasGroup> ();

     float rate = 1.0f / fadeTime;

     int startAlpha = 0;
     int endAlpha = 1;


     for (int i = 0; i < 2; i++)
     {
         float progress = 0.0f;
         while (progress < 1.0)
         {
             canvasGroup.alpha = Mathf.Lerp (startAlpha, endAlpha, progress);

             progress += rate * Time.deltaTime;

             yield return null;

         }
         yield return new WaitForSeconds (2);
         startAlpha = 1;
         endAlpha = 0;
     }

     Destroy (achievent);

 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

The given key was not present in the dictionary, i am calling the key immediately after adding it 1 Answer

Dictionary within a dictionary? 1 Answer

ES2 Can't save Dictionary 1 Answer

Dictionary.TryGetValue throwing an error DivideByZeroException: Division by zero 2 Answers

KeyNotFoundException that makes no sense (*I* can find the key) 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges