Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug "Item with the same key has already been added" when using index operator to replace a local variabl

Discussion in 'Localization Tools' started by geordiemhall, Mar 24, 2022.

  1. geordiemhall

    geordiemhall

    Joined:
    Jun 6, 2020
    Posts:
    20
    When using the indexing operator on a `LocalizedString` to set a new value for a local variable, I'd expect it to behave the same as a `Dictionary<T>` instead of throwing an ArgumentException.

    Eg.
    Code (CSharp):
    1. // If "VariableName" already existed, it should be replaced silently
    2. _locString["VariableName"] = someOtherLocString;
    3.  
    4. // But this should throw, this `Dictionary<T>`'s .Add() API only allows adding new keys
    5. _locString.Add("VariableName", someOtherLocString);
    6.  
    For now I'm just removing the key before re-adding to change its value, eg.
    Code (CSharp):
    1. _locStringEvent.StringReference.Remove("VariableName");
    2. _locStringEvent.StringReference["VariableName"] = newValue;
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,846
    Ah thanks for the feedback. I'll get this changed.
     
  3. geordiemhall

    geordiemhall

    Joined:
    Jun 6, 2020
    Posts:
    20
    Great, thanks!