I’m creating a card game in Unity and trying to use TextMesh Pro with the font Baloo. I have created a regular version plus 4 others with an outline of different colours used to highlight important information via . Using these in the editor, there seems to be no issue, however the first time I set text at runtime that includes <font=“Baloo-O[colour]”>, I get the following errors:
ArgumentException: An item with the same key has already been added. Key: -324971240
System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <fb001e01371b4adca20013e0ac763896>:0)
System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <fb001e01371b4adca20013e0ac763896>:0)
TMPro.MaterialReferenceManager.AddFontAssetInternal (TMPro.TMP_FontAsset fontAsset) (at Library/PackageCache/com.unity.textmeshpro@2.1.0/Scripts/Runtime/MaterialReferenceManager.cs:56)
TMPro.MaterialReferenceManager.AddFontAsset (TMPro.TMP_FontAsset fontAsset) (at Library/PackageCache/com.unity.textmeshpro@2.1.0/Scripts/Runtime/MaterialReferenceManager.cs:41)
TMPro.TMP_Text.ValidateHtmlTag (TMPro.TMP_Text+UnicodeChar[] chars, System.Int32 startIndex, System.Int32& endIndex) (at Library/PackageCache/com.unity.textmeshpro@2.1.0/Scripts/Runtime/TMP_Text.cs:8665)
TMPro.TextMeshPro.SetArraySizes (TMPro.TMP_Text+UnicodeChar[] unicodeChars) (at Library/PackageCache/com.unity.textmeshpro@2.1.0/Scripts/Runtime/TMPro_Private.cs:1051)
TMPro.TMP_Text.ParseInputText () (at Library/PackageCache/com.unity.textmeshpro@2.1.0/Scripts/Runtime/TMP_Text.cs:1893)
TMPro.TextMeshPro.OnPreRenderObject () (at Library/PackageCache/com.unity.textmeshpro@2.1.0/Scripts/Runtime/TMPro_Private.cs:1521)
TMPro.TextMeshPro.Rebuild (UnityEngine.UI.CanvasUpdate update) (at Library/PackageCache/com.unity.textmeshpro@2.1.0/Scripts/Runtime/TextMeshPro.cs:274)
TMPro.TMP_UpdateManager.DoRebuilds () (at Library/PackageCache/com.unity.textmeshpro@2.1.0/Scripts/Runtime/TMP_UpdateManager.cs:171)
UnityEngine.Canvas.SendWillRenderCanvases () (at <4af5bea1b7b2442494fd73f6f9b3d7f4>:0)
NullReferenceException: Object reference not set to an instance of an object
TMPro.TextMeshPro.GenerateTextMesh () (at Library/PackageCache/com.unity.textmeshpro@2.1.0/Scripts/Runtime/TMPro_Private.cs:1985)
TMPro.TextMeshPro.OnPreRenderObject () (at Library/PackageCache/com.unity.textmeshpro@2.1.0/Scripts/Runtime/TMPro_Private.cs:1553)
TMPro.TextMeshPro.Rebuild (UnityEngine.UI.CanvasUpdate update) (at Library/PackageCache/com.unity.textmeshpro@2.1.0/Scripts/Runtime/TextMeshPro.cs:274)
TMPro.TMP_UpdateManager.DoRebuilds () (at Library/PackageCache/com.unity.textmeshpro@2.1.0/Scripts/Runtime/TMP_UpdateManager.cs:171)
UnityEngine.Canvas.SendWillRenderCanvases () (at <4af5bea1b7b2442494fd73f6f9b3d7f4>:0)
If I rerun the function that sets the text a second time, it works fine! It’s just the first time it’s called. I have tried:
-
Deleting the TextMesh Pro folder from the Assets folder, reimporting it and scanning for fonts (which had no results as it was created with the same version 2.1.0)
-
Deleting and recreating the font asset through both the right-click → Create → TextMeshPro → Font Asset and the Font Asset Creator window
-
Using static or dynamic font options (not sure what it would do but worth a try) including fallbacks
Using the default LiberationSans SDF works fine so I can only assume there must be , but I don’t know what else I can try. I’m not classifying this as a bug just yet in case I’m doing something wrong.