Everything was working as expected. Today I added a new font as fallback and started getting this error:
Non-fatal Exception: java.lang.Exception: ArgumentException : An item with the same key has already been added. Key: 0
at System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert(System.Collections.Generic.Dictionary`2[TKey,TValue])
at TMPro.TMP_FontAsset.InitializeDictionaryLookupTables(TMPro.TMP_FontAsset)
at TMPro.TMP_FontAsset.ReadFontAssetDefinition(TMPro.TMP_FontAsset)
at TMPro.TMP_FontAssetUtilities.GetCharacterFromFontAsset_Internal(TMPro.TMP_FontAssetUtilities)
at TMPro.TMP_FontAssetUtilities.GetCharacterFromFontAssets(TMPro.TMP_FontAssetUtilities)
at TMPro.TextMeshProUGUI.SetArraySizes(TMPro.TextMeshProUGUI)
at TMPro.TMP_Text.GetPreferredWidth(TMPro.TMP_Text)
at TMPro.TextMeshProUGUI.CalculateLayoutInputHorizontal(TMPro.TextMeshProUGUI)
at UnityEngine.Events.UnityAction`1[T0].Invoke(UnityEngine.Events.UnityAction`1[T0])
at UnityEngine.UI.LayoutRebuilder.PerformLayoutCalculation(UnityEngine.UI.LayoutRebuilder)
at UnityEngine.UI.LayoutRebuilder.PerformLayoutCalculation(UnityEngine.UI.LayoutRebuilder)
at UnityEngine.UI.LayoutRebuilder.PerformLayoutCalculation(UnityEngine.UI.LayoutRebuilder)
at UnityEngine.UI.LayoutRebuilder.Rebuild(UnityEngine.UI.LayoutRebuilder)
at UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate(UnityEngine.UI.CanvasUpdateRegistry)
at UnityEngine.Canvas+WillRenderCanvases.Invoke(UnityEngine.Canvas+WillRenderCanvases)
at UnityEngine.WillRenderCanvases:Invoke(UnityEngine)
I deleted the plugin folder and TMP showed the “Download Essential Resources” popup. I did it, reinstalled it and the exception is not thrown anymore. I saw the version above (2.0.1) in the Package Manager window, but I’m not sure if I’m actually using it as I downloaded TMP when it was available at the Asset Store.
@Stephan_B
I’m getting this same error, in Version 2.01, in Unity 2019.2.11f1. It seems to be on the FontAsset, of a TMPro Text item. I added a couple of texts to the UI Panel in my project, selected a font asset that I created using the Font Asset creator window. I’m not using a downloaded version, I’m using it from the package manager.
This is the error (times 2) that comes up, every time Unity recompiles my project, because of me updating my code. It also does it on run, inside of the editor.
When I double click the error, it takes me to the text object in the scene, not to the source code or compiled code in the package.
ArgumentException: An item with the same key has already been added. Key: 0
System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <567df3e0919241ba98db88bec4c6696f>:0)
System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <567df3e0919241ba98db88bec4c6696f>:0)
TMPro.TMP_FontAsset.InitializeDictionaryLookupTables () (at Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Runtime/TMP_FontAsset.cs:589)
TMPro.TMP_FontAsset.ReadFontAssetDefinition () (at Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Runtime/TMP_FontAsset.cs:607)
TMPro.TMP_FontAsset.get_characterLookupTable () (at Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Runtime/TMP_FontAsset.cs:139)
TMPro.TextMeshProUGUI.LoadFontAsset () (at Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Runtime/TMPro_UGUI_Private.cs:539)
TMPro.TextMeshProUGUI.OnValidate () (at Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Runtime/TMPro_UGUI_Private.cs:302)
Always package manager for Unity 2018 or Newer… stay away from AssetStore version which is the Legacy / old version which is no longer being updated.
@Stephan_B Just a side note…
The Top alignment and Left alignment (default, unchanged) for text has a horrid tendency to move all of the text outside of the text area. Also, whenever I update to the newest release in the Package Manager, it goes through and screws up the settings of existing TMP Text objects in all of the scenes in my game. It did these issues in Preview-7… I’m hoping that Preview 8 doesn’t do that, or my day is going to be spent fixing text boxes. lol.
Hi, I am still receiving this error (the original error posted in this thread) in my project about TextMeshPro (as seen in the posted image). I have created a new custom font using the correct method. Do you know why this happens?
Please make sure you are using the latest release of the TMP package which is Preview 13. Also make sure you update the TMP Essential Resources which contains updated files and shaders.