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

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.

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.

Hi,

I uploaded the TextMeshPro to the latest version (2.0.1), but the error is still here.

https://send.firefox.com/download/548ea0439da8ccd2/#nYKB-PztkkOSj96cyctuqg

Regards, Samih.

Do you have a backup of the Font Asset prior to upgrading to 2019.1? The one your provided above as already been converted to the new format.

Hi,

This is the Font Asset from my backup, before i upgraded to 2019.1.

https://send.firefox.com/download/9ab197a75612cd34/#ipWXKd192Yytp53aHarCOw

Regards, Samih.

1 Like

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.

3 Likes

Hi,

it worked as you said.

Thanks a lot!

Regards, Samih.

2 Likes

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

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.

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?

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.

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.

5514859–566134–TextMeshProBug.zip (1.72 MB)

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.

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.

3 Likes

Thank you - that worked perfectly.

I had the same problem, can confirm that preview 5 removed it, thank you

1 Like

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”>

The latest release for Unity 2018.4 is version 1.5.0-preview.11 where this issue should be resolved.

@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)

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.