Search Unity

TextMeshPro UGUI - An item with the same key has already been added

Discussion in 'UGUI & TextMesh Pro' started by kaisersam, May 26, 2019.

  1. kaisersam

    kaisersam

    Joined:
    Mar 31, 2016
    Posts:
    39
    Hi,

    I just switch a project from Unity 2018.3.0f2 to 2019.1.3f1, and i'm having an error on a GameObject with a TextMeshProUGUI component.


    ArgumentException: An item with the same key has already been added. Key: 249108103171
    System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <1f0c1ef1ad524c38bbc5536809c46b48>:0)
    System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <1f0c1ef1ad524c38bbc5536809c46b48>:0)
    TMPro.TMP_FontAsset.InitializeDictionaryLookupTables () (at Library/PackageCache/com.unity.textmeshpro@2.0.0/Scripts/Runtime/TMP_FontAsset.cs:584)
    TMPro.TMP_FontAsset.ReadFontAssetDefinition () (at Library/PackageCache/com.unity.textmeshpro@2.0.0/Scripts/Runtime/TMP_FontAsset.cs:602)
    TMPro.TMP_FontAsset.UpgradeFontAsset () (at Library/PackageCache/com.unity.textmeshpro@2.0.0/Scripts/Runtime/TMP_FontAsset.cs:1847)
    TMPro.TMP_FontAsset.Awake () (at Library/PackageCache/com.unity.textmeshpro@2.0.0/Scripts/Runtime/TMP_FontAsset.cs:482)


    I saw that a font has the same local identifier in file value, and it triggers this error.

    How could i change this value?

    Thanks a lot.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    This is related to Glyph Adjustment Pairs (Kerning Pairs).

    Can you provide me with the backup of the Font Asset that is producing these errors? Make sure it is the version of the asset prior to upgrading to 2019.x.
     
  3. kaisersam

    kaisersam

    Joined:
    Mar 31, 2016
    Posts:
    39
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
  5. kaisersam

    kaisersam

    Joined:
    Mar 31, 2016
    Posts:
    39
    Stephan_B likes this.
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    In version 1.4.1 and 2.0.1, I did make a change to avoid this issue. However in your case, the font asset's Glyph Adjustment Table was already converted in version 1.4.0 or 2.0.0 which is why you are getting this issue.

    Depending on how many font assets you have, I would suggest taking the older version of the font asset (like you just provided me) and replacing the already converted ones by the older ones. This will re-convert them in 2.0.1 where everything will work as expected.

    I will also make additional changes to try to handle this more gracefully for users who end up in the same situation.

    Let me know if reverting / re-importing the older versions is a workable solution for you and if that worked as expected.

    You will get a console message when these are converted again.
     
  7. kaisersam

    kaisersam

    Joined:
    Mar 31, 2016
    Posts:
    39
    Hi,

    it worked as you said.

    Thanks a lot!

    Regards, Samih.
     
    WinterboltGames and Stephan_B like this.
  8. SkyGolem

    SkyGolem

    Joined:
    Oct 13, 2018
    Posts:
    2
    I do have the exact same error message except I created the project in unity 2019 and never converted. I do not quite understand, what you mean by reverting / re-importing. Thx for help in advance
     
  9. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    As usual make sure you backup the project first.

    Then see if the issue persists using the latest release of the TMP package which is version 2.1.0-preview.4 for Unity 2019.x.
     
  10. Redrag

    Redrag

    Joined:
    Apr 27, 2014
    Posts:
    181
    I have the same issue when changing a font to one with Cyrillic characters during runtime. Unity 2019.2.17f1. The font has been created using this version. Are you suggesting I download an older version of Unity just to create a font that actually works? If so which version would you recommend?
     
  11. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    What version of the TMP package are you using?

    If you are using the latest version which is 2.1.0-preview.4 for Unity 2019.x, please provide me with a simple reproduction project / scene so I can figure out what this behavior is still occurring.

    I am getting ready to release preview 5 and could actually address that quickly before.

    If you can reproduce these steps easily in the latest release, them please provide those instead if that is easier for you.Otherwise, you can submit a bug report with the included project and steps and once you get the case # back from Unity via email, please provide that case # to me.
     
  12. Redrag

    Redrag

    Joined:
    Apr 27, 2014
    Posts:
    181
    I made a sample project and got the same error. However I noticed that my TMP seems to be out of date. I'm not sure why as I have downloaded Unity 2019.2.17f1 recently.

    When I added a TMP object, I was given the option to import the various TMP stuff. Under Assets I have 'TextMesh Pro' folder with fonts, documentation etc. The documentation is dated 2016.

    Under Packages I have 'TextMesh Pro' witht he ChangeLog showing the latest version as 2.0.1

    I have tried reimporting both folders but the errors persist.

    If the problem is an out of date TMP could you let me know how to update it?

    Sample project attached.
     

    Attached Files:

  13. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    That is the same documentation which hasn't been updated in ages so that is likely fine.

    The Package Manager would tell you what version you have which should correspond to 2.0.1 as this should mirror the ChangeLog.

    I will take a look at your repro project and provide feedback as soon as I have more information.
     
    Last edited: Feb 25, 2020
  14. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I was able to observe the issue in the repro project you provided. This issue was resolved in one of the preview release of version 2.1.0 of the TMP package which are currently available via the package manager.

    Please install version 2.1.0-preview.4 of the TMP package. You might need to enable the "Show preview packages" in the Advanced tab of the package manager window.

    P.S. Preview 5 should be available this week / within the next few days.
     
  15. Redrag

    Redrag

    Joined:
    Apr 27, 2014
    Posts:
    181
    Thank you - that worked perfectly.
     
  16. CameronOtten

    CameronOtten

    Joined:
    Apr 1, 2015
    Posts:
    12
    I had the same problem, can confirm that preview 5 removed it, thank you
     
    Stephan_B likes this.
  17. MohammadAlizadeh

    MohammadAlizadeh

    Joined:
    Apr 16, 2015
    Posts:
    26
    What about the 2018 users and any workaround about this error
    Feels like there's an easy fix, it has to be something with the dictionary registering them.

    it happens randomly when instantiating it parented to an object.

    EDIT:
    mostly happens when you use custom font tags <font="myfont">
     
    Last edited: Apr 24, 2020
  18. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The latest release for Unity 2018.4 is version 1.5.0-preview.11 where this issue should be resolved.
     
  19. zackblack

    zackblack

    Joined:
    May 17, 2015
    Posts:
    76
    @Stephan_B The bug was reported back in February and TMP is up to preview.12 now. Why hasn't this been pushed to a non-preview version? I tried both preview.5 and preview.12 and now I get this:

    NullReferenceException: Object reference not set to an instance of an object
    TMPro.TMP_SubMesh.OnDestroy () (at Library/PackageCache/com.unity.textmeshpro@2.1.0-preview.5/Scripts/Runtime/TMP_SubMesh.cs:295)
     
  20. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    This will be addressed in Preview 13 and is related to a workflow that involves enabling / disabling Canvases.See the following thread which includes a solution for that issue until Preview 13 is available which should be over the weekend.

    It is still in Preview since some issues are still being reported although very few now so I am hopeful Preview 13 might be the last one.
     
  21. Deleted User

    Deleted User

    Guest

    michele_bonapace likes this.
  22. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    What version of the TMP package are you using? This should have been addressed in newer releases of the TMP package where the latest is Preview 13.

    In terms of making changes to the source code, these need to be made in the Global Package Cache otherwise your changes will be overwritten whenever you re-start Unity.
     
  23. TheD0gRex

    TheD0gRex

    Joined:
    Jun 10, 2020
    Posts:
    1
    @Stephan_B Thanks a lot!

    I've installed Text Mesh Pro version 2.1.0-preview.5 via Package Manager. And it helps me!
     
  24. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Latest release is 2.1.0-preview.14 and as such I would recommend switching to that release.
     
  25. molor824

    molor824

    Joined:
    Jun 10, 2020
    Posts:
    4
    2.1.0 is a preview and its not fully released version so that's why it might be showing error. I tried 2.0.0 (which is not preview version) and it had no error
     
  26. jamirokwai

    jamirokwai

    Joined:
    Feb 17, 2015
    Posts:
    1
    Hi, I'm late to the party, but I think, I found a way to fix this.

    0. I am on a Mac.
    1. Create a new font-asset from your ttf.
    2. Let Unity show the new asset in Finder (Sorry, don't know the windows-option).
    3. Move the OLD font-asset out of the project. Or delete it right away.
    4. Rename the NEW one to fit the name of the old one.
    5. Go back to Unity and wait for checking the file.

    In my project, this just replaced the old font-asset. Oddly, the files were a lot smaller as well, so I assume there were some errors in the old, larger font-assets.

    Cheers
    J.
     
    Starbox likes this.
  27. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    This issue should be resolved in the latest releases of the TMP package.

    The latest releases are version 1.5.3 for Unity 2018.4, version 2.1.3 for Unity 2019.4 and version 3.0.3 for Unity 2020.x or newer.
     
  28. IsSchoGuat

    IsSchoGuat

    Joined:
    Dec 29, 2019
    Posts:
    4
    Hello, anyone can help me with this fault? It comes when i try to adjust the script execution order.

    "
    ArgumentException: An item with the same key has already been added. Key: Packages/com.unity.analytics/Unity.Analytics.Tracker.dll.meta
    System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <9577ac7a62ef43179789031239ba8798>:0)
    System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <9577ac7a62ef43179789031239ba8798>:0)
    UnityEditor.ScriptExecutionOrderInspector.ShowScriptPopup (UnityEngine.Rect r) (at <a936841cea2147a2a55ea27843fa46ae>:0)
    UnityEditor.ScriptExecutionOrderInspector.OnInspectorGUI () (at <a936841cea2147a2a55ea27843fa46ae>:0)
    UnityEditor.AssetSettingsProvider.OnGUI (System.String searchContext) (at <a936841cea2147a2a55ea27843fa46ae>:0)
    UnityEditor.SettingsWindow.DrawControls () (at <a936841cea2147a2a55ea27843fa46ae>:0)
    UnityEditor.SettingsWindow.DrawSettingsPanel () (at <a936841cea2147a2a55ea27843fa46ae>:0)
    UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <52128b1d503447a983e9b80962adef7d>:0)
    UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <52128b1d503447a983e9b80962adef7d>:0)
    UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <52128b1d503447a983e9b80962adef7d>:0)
    UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, System.Boolean canAffectFocus) (at <52128b1d503447a983e9b80962adef7d>:0)
    UnityEngine.UIElements.IMGUIContainer.SendEventToIMGUIRaw (UnityEngine.UIElements.EventBase evt, System.Boolean canAffectFocus, System.Boolean verifyBounds) (at <52128b1d503447a983e9b80962adef7d>:0)
    UnityEngine.UIElements.IMGUIContainer.SendEventToIMGUI (UnityEngine.UIElements.EventBase evt, System.Boolean canAffectFocus, System.Boolean verifyBounds) (at <52128b1d503447a983e9b80962adef7d>:0)
    UnityEngine.UIElements.IMGUIContainer.HandleEvent (UnityEngine.UIElements.EventBase evt) (at <52128b1d503447a983e9b80962adef7d>:0)
    UnityEngine.UIElements.EventDispatchUtilities.PropagateEvent (UnityEngine.UIElements.EventBase evt) (at <52128b1d503447a983e9b80962adef7d>:0)
    UnityEngine.UIElements.MouseEventDispatchingStrategy.SendEventToRegularTarget (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel) (at <52128b1d503447a983e9b80962adef7d>:0)
    UnityEngine.UIElements.MouseEventDispatchingStrategy.SendEventToTarget (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel) (at <52128b1d503447a983e9b80962adef7d>:0)
    UnityEngine.UIElements.MouseEventDispatchingStrategy.DispatchEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel iPanel) (at <52128b1d503447a983e9b80962adef7d>:0)
    UnityEngine.UIElements.EventDispatcher.ApplyDispatchingStrategies (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, System.Boolean imguiEventIsInitiallyUsed) (at <52128b1d503447a983e9b80962adef7d>:0)
    UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <52128b1d503447a983e9b80962adef7d>:0)
    UnityEngine.UIElements.EventDispatcher.ProcessEventQueue () (at <52128b1d503447a983e9b80962adef7d>:0)
    UnityEngine.UIElements.EventDispatcher.OpenGate () (at <52128b1d503447a983e9b80962adef7d>:0)
    UnityEngine.UIElements.EventDispatcherGate.Dispose () (at <52128b1d503447a983e9b80962adef7d>:0)
    UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <52128b1d503447a983e9b80962adef7d>:0)
    UnityEngine.UIElements.EventDispatcher.Dispatch (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, UnityEngine.UIElements.DispatchMode dispatchMode) (at <52128b1d503447a983e9b80962adef7d>:0)
    UnityEngine.UIElements.BaseVisualElementPanel.SendEvent (UnityEngine.UIElements.EventBase e, UnityEngine.UIElements.DispatchMode dispatchMode) (at <52128b1d503447a983e9b80962adef7d>:0)
    UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at <52128b1d503447a983e9b80962adef7d>:0)
    UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& eventHandled) (at <52128b1d503447a983e9b80962adef7d>:0)
    UnityEngine.UIElements.UIEventRegistration.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <52128b1d503447a983e9b80962adef7d>:0)
    UnityEngine.UIElements.UIEventRegistration+<>c.<.cctor>b__1_2 (System.Int32 i, System.IntPtr ptr) (at <52128b1d503447a983e9b80962adef7d>:0)
    UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& result) (at <f8197c5efb504ab8a77daf7d0e9abc5e>:0)

    "
     
  29. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    467
    I just recently fiddled with a font atlas and for some reason something got broken in the process. I had this:

    Code (CSharp):
    1. ArgumentException: An item with the same key has already been added. Key: 0
    2. System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <9577ac7a62ef43179789031239ba8798>:0)
    3. System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <9577ac7a62ef43179789031239ba8798>:0)
    4. TMPro.TMP_FontAsset.InitializeDictionaryLookupTables () (at Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Runtime/TMP_FontAsset.cs:589)
    5. TMPro.TMP_FontAsset.ReadFontAssetDefinition () (at Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Runtime/TMP_FontAsset.cs:607)
    6. TMPro.TMP_FontAsset.get_characterLookupTable () (at Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Runtime/TMP_FontAsset.cs:139)
    7. TMPro.TextMeshProUGUI.LoadFontAsset () (at Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Runtime/TMPro_UGUI_Private.cs:539)
    8. TMPro.TextMeshProUGUI.Awake () (at Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Runtime/TMPro_UGUI_Private.cs:117)
    9. UnityEngine.GameObject:SetActive(Boolean)
    I went back into a fresh archive and brought back the file and followed your method, it worked like a charm and this was most fortunate because I didn't understand a single thing of what was explained before in this thread. :D