title: key not present error
body: <p>From my understanding what should be happening here is explained in the comments but for some reason I get this error in the editor</p>
  
  <blockquote>
    <p>KeyNotFoundException: The given key was not present in the dictionary.
    System.Collections.Generic.Dictionary`2[System.Int32,System.String].get_Item
    (Int32 key) (at
    /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:150)
    UpgradeManager.ScanForAvailableUpgrades () (at 
    Assets/Scripts/UpgradeManager.cs:125 UpgradeManager.Update () (at
    Assets/Scripts/UpgradeManager.cs:70)</p>
  </blockquote>
  
  <p>The error happens after the function <code>DisableSameType</code> is called</p>
  
  <pre class="lang-c# prettyprint-override"><code>public string GetUpgradeType(string upgradeName){
          return upgradeTypes [upgradeName];
      }
  
      public void DisableSameType (string upgradeName){
          string upgradeType = GetUpgradeType (upgradeName);
  
          string[] keys = KeyByValue (upgradeTypes, upgradeType); //returns all the keys of the same type
  
          if (keys.Length == 0) { //if there are no keys
              return;             //then return
          } else {
              for (int i = 0; i &lt; keys.Length; i++) { //loop through all the keys
                  upgradesOwned [keys [i]] = false;   //Set them to false
              }
          }
      }
  </code></pre>
  
  
  
  <p>And here are other relevant code</p>
  
  <pre class="lang-c# prettyprint-override"><code>public List&lt;string&gt; AvailableUpgrades = new List&lt;string&gt;();
  
      protected Dictionary&lt;int,string&gt; upgradeNames = new Dictionary&lt;int, string&gt;();
  
      protected Dictionary&lt;string,bool&gt; upgradesOwned = new Dictionary&lt;string, bool&gt;();
      protected Dictionary&lt;string,bool&gt; upgradesPurchased = new Dictionary&lt;string, bool&gt;();
  
      protected Dictionary&lt;string,int&gt; upgradeCost = new Dictionary&lt;string, int&gt;(); 
  
      /* UPGRADE TYPES
       * Title
       * Layout
       * Scoreboard
       * VisualCountdown
       */
      protected Dictionary&lt;string,string&gt; upgradeTypes = new Dictionary&lt;string, string&gt;();
  
  protected bool IsPurchased(string upgradeName){
      return upgradesPurchased [upgradeName];
  }
  
  public static string[] KeyByValue(Dictionary&lt;string, string&gt; dict, string val)
      {
          string key = null;
          foreach (KeyValuePair&lt;string, string&gt; pair in dict)
          {
              if (pair.Value == val)
              { 
                  key += pair.Key + "|"; 
                  break; 
              }
          }
          return key.Split('|');
      }
  
  protected void ScanForAvailableUpgrades(){
          AvailableUpgrades.Clear ();                                             //Clear the list
          int scanRange = GetUnits() + GameManager.Instance.scanRange;            //Get the range by adding the scanRange to current units
          for (int i = 0; i &lt; upgradesOwned.Count; i++) {                     //Loop through all upgrades
              if (IsPurchased (upgradeNames [i])) {
                  //return
              } else {
                  if (scanRange &gt;= upgradeCost [upgradeNames [i]]) {                      //Check if the cost is within the scanrange
                      if (AvailableUpgrades.Contains (upgradeNames [i])) {                //Check if upgrade is already in the available list
                          //return;                                                   //If it is we just return
                      } else {                                                        //Else
                          if (upgradesOwned [upgradeNames [i]]) {                 //Check if the user already has the upgrade *NOTE* Should probaby check for this first to improve performance
                              //return;                                               //If it is return
                          } else {                                                    //Else
                              AvailableUpgrades.Add (upgradeNames [i]);                   //Upgrade does not exist and is not bought so add it to the available list
                          }
                      }
                  }
              }
          }
      }
  </code></pre>
  
  
  
  <p>after further debugging i have found out that <code>Debug.Log(keys[i]);</code> is returning the first string as "basicTitle|" and the string string is blank</p>
  
  <p>EDIT:
  I can see where my question can seem misleading line 125 is this line <code>if (IsPurchased (upgradeNames [i])) {</code> however Ive already gone through and after commenting out "DisableSameType" the error goes away the method <code>DisableSameType</code> is a new function and the error didnt start happening till it was implemented so I am 100% positive this is the source of the error im just not sure what is causing it</p>