UIBuilder/UIToolkit doesn't work with Japanese text when label has text wrap on

I created a new project in 2020.1.17f1 (also replicated in 2020.2.1f1) with UIBuilder 11 and UIToolkit 13. If I try creating a Label in the UIBuilder with text wrap on, and then set the text to something in Japanese, then errors repeatedly appear in the console in either CalculatePreferredValues or GenerateTextMesh. If I set the text to something in English and then change it at runtime into Japanese, the same errors appear.
Everything works if the text wrap is set to nowrap.

It seems to be due to the properties leadingCharactersLookup/followingCharactersLookup not being set, which should correspond to the “Line Breaking for Asian languages” option in the Panel Text Settings, but setting these does not change anything.

I was using UIBuilder 9 and UIToolkit 9 before, and those versions worked.

The stack trace looks like this.

NullReferenceException: Object reference not set to an instance of an object
UnityEngine.TextCore.Text.TextGenerator.CalculatePreferredValues (System.Single defaultFontSize, UnityEngine.Vector2 marginSize, System.Boolean ignoreTextAutoSizing, UnityEngine.TextCore.Text.TextGenerationSettings generationSettings, UnityEngine.TextCore.Text.TextInfo textInfo) (at Library/PackageCache/com.unity.textcore@1.0.0-preview.2/Scripts/Runtime/TextGenerator.cs:5813)
UnityEngine.TextCore.Text.TextGenerator.GetPreferredValuesInternal (UnityEngine.TextCore.Text.TextGenerationSettings generationSettings, UnityEngine.TextCore.Text.TextInfo textInfo) (at Library/PackageCache/com.unity.textcore@1.0.0-preview.2/Scripts/Runtime/TextGenerator.cs:5253)
UnityEngine.TextCore.Text.TextGenerator.GetPreferredValues (UnityEngine.TextCore.Text.TextGenerationSettings settings, UnityEngine.TextCore.Text.TextInfo textInfo) (at Library/PackageCache/com.unity.textcore@1.0.0-preview.2/Scripts/Runtime/TextGenerator.cs:400)
UnityEngine.UIElements.Text.TextCoreHandle.UpdatePreferredValues (UnityEngine.UIElements.MeshGenerationContextUtils+TextParams parms) (at Library/PackageCache/com.unity.ui@1.0.0-preview.13/Text/TextCoreHandle.cs:177)
UnityEngine.UIElements.Text.TextCoreHandle.ComputeTextHeight (UnityEngine.UIElements.MeshGenerationContextUtils+TextParams parms, System.Single scaling) (at Library/PackageCache/com.unity.ui@1.0.0-preview.13/Text/TextCoreHandle.cs:88)
UnityEngine.UIElements.TextUtilities.MeasureVisualElementTextSize (UnityEngine.UIElements.VisualElement ve, System.String textToMeasure, System.Single width, UnityEngine.UIElements.VisualElement+MeasureMode widthMode, System.Single height, UnityEngine.UIElements.VisualElement+MeasureMode heightMode, UnityEngine.UIElements.ITextHandle textHandle) (at Library/PackageCache/com.unity.ui@1.0.0-preview.13/Core/Text/TextHandle.cs:400)
UnityEngine.UIElements.TextElement.MeasureTextSize (System.String textToMeasure, System.Single width, UnityEngine.UIElements.VisualElement+MeasureMode widthMode, System.Single height, UnityEngine.UIElements.VisualElement+MeasureMode heightMode) (at Library/PackageCache/com.unity.ui@1.0.0-preview.13/Core/TextElement.cs:320)
UnityEngine.UIElements.TextElement.DoMeasure (System.Single desiredWidth, UnityEngine.UIElements.VisualElement+MeasureMode widthMode, System.Single desiredHeight, UnityEngine.UIElements.VisualElement+MeasureMode heightMode) (at Library/PackageCache/com.unity.ui@1.0.0-preview.13/Core/TextElement.cs:335)
UnityEngine.UIElements.VisualElement.Measure (UnityEngine.Yoga.YogaNode node, System.Single width, UnityEngine.Yoga.YogaMeasureMode widthMode, System.Single height, UnityEngine.Yoga.YogaMeasureMode heightMode) (at Library/PackageCache/com.unity.ui@1.0.0-preview.13/Core/VisualElement.cs:1532)
UnityEngine.UIElements.VisualElement.<AssignMeasureFunction>b__335_0 (UnityEngine.Yoga.YogaNode node, System.Single f, UnityEngine.Yoga.YogaMeasureMode mode, System.Single f1, UnityEngine.Yoga.YogaMeasureMode heightMode) (at Library/PackageCache/com.unity.ui@1.0.0-preview.13/Core/VisualElement.cs:1516)
UnityEngine.Yoga.YogaNode.MeasureInternal (UnityEngine.Yoga.YogaNode node, System.Single width, UnityEngine.Yoga.YogaMeasureMode widthMode, System.Single height, UnityEngine.Yoga.YogaMeasureMode heightMode) (at <a60568d854ce4242b925658dfd58b04f>:0)
UnityEngine.Yoga.Native.YGNodeMeasureInvoke (UnityEngine.Yoga.YogaNode node, System.Single width, UnityEngine.Yoga.YogaMeasureMode widthMode, System.Single height, UnityEngine.Yoga.YogaMeasureMode heightMode, System.IntPtr returnValueAddress) (at <a60568d854ce4242b925658dfd58b04f>:0)
UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

Or alternatively

NullReferenceException: Object reference not set to an instance of an object
UnityEngine.TextCore.Text.TextGenerator.GenerateTextMesh (UnityEngine.TextCore.Text.TextGenerationSettings generationSettings, UnityEngine.TextCore.Text.TextInfo textInfo) (at Library/PackageCache/com.unity.textcore@1.0.0-preview.2/Scripts/Runtime/TextGenerator.cs:1694)
UnityEngine.TextCore.Text.TextGenerator.GenerateText (UnityEngine.TextCore.Text.TextGenerationSettings settings, UnityEngine.TextCore.Text.TextInfo textInfo) (at Library/PackageCache/com.unity.textcore@1.0.0-preview.2/Scripts/Runtime/TextGenerator.cs:315)
UnityEngine.UIElements.Text.TextCoreHandle.Update (UnityEngine.UIElements.MeshGenerationContextUtils+TextParams parms, System.Single pixelsPerPoint) (at Library/PackageCache/com.unity.ui@1.0.0-preview.13/Text/TextCoreHandle.cs:134)
UnityEngine.UIElements.UIR.Implementation.UIRStylePainter.DrawTextCore (UnityEngine.UIElements.MeshGenerationContextUtils+TextParams textParams, UnityEngine.UIElements.ITextHandle handle, System.Single pixelsPerPoint) (at Library/PackageCache/com.unity.ui@1.0.0-preview.13/Core/Renderer/UIRStylePainter.cs:389)
UnityEngine.UIElements.Text.TextCoreHandle.DrawText (UnityEngine.UIElements.UIR.Implementation.UIRStylePainter painter, UnityEngine.UIElements.MeshGenerationContextUtils+TextParams textParams, System.Single pixelsPerPoint) (at Library/PackageCache/com.unity.ui@1.0.0-preview.13/Text/TextCoreHandle.cs:116)
UnityEngine.UIElements.UIR.Implementation.UIRStylePainter.DrawText (UnityEngine.UIElements.MeshGenerationContextUtils+TextParams textParams, UnityEngine.UIElements.ITextHandle handle, System.Single pixelsPerPoint) (at Library/PackageCache/com.unity.ui@1.0.0-preview.13/Core/Renderer/UIRStylePainter.cs:359)
UnityEngine.UIElements.MeshGenerationContextUtils.Text (UnityEngine.UIElements.MeshGenerationContext mgc, UnityEngine.UIElements.MeshGenerationContextUtils+TextParams textParams, UnityEngine.UIElements.ITextHandle handle, System.Single pixelsPerPoint) (at Library/PackageCache/com.unity.ui@1.0.0-preview.13/Core/Renderer/UIRMeshGenerationContext.cs:721)
UnityEngine.UIElements.TextElement.OnGenerateVisualContent (UnityEngine.UIElements.MeshGenerationContext mgc) (at Library/PackageCache/com.unity.ui@1.0.0-preview.13/Core/TextElement.cs:176)
UnityEngine.UIElements.VisualElement.InvokeGenerateVisualContent (UnityEngine.UIElements.MeshGenerationContext mgc) (at Library/PackageCache/com.unity.ui@1.0.0-preview.13/Core/VisualElement.cs:1317)
UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

Can you please report a bug from Unity?

Sure, I filed Case 1305483.

I got the same~
Have any news for your report?

1 Like

This turned out to be a major problem for our project. We are in the middle of migrating a project to UI Toolkit and just received translation files from the localization company. Japanese, Korean and Simplified Chinese crash with the same error as OP.

We are on Unity 2020.3.0f1, com.unity.ui 1.0.0-preview.14.

@antoine-unity Has the fix been backported to Unity 2021.1? If not, we need your team’s assistance with the problem.

The fix is present in 2021.2 where UI Toolkit is builtin. For 2021.1 and earlier, UI Toolkit for Runtime is only available through the preview package.

The fix will be present in a future version of the preview package. At the moment I cannot say when this new version will be available.

I will reach out to the team and see if there is a possible workaround.

We have just tested version 2021.2.0a13 and the problem is still present. You can reproduce it by adding a Label with at least two Japanese characters and white-space set to “normal”.

We’ve also submitted a bug report with a repro.

Versions 2021.2.0a14 and 2021.2.0a15 seem to working fine, although they have multiple other stability problems which make it impossible to migrate to the 2021.2 branch at this time.

Thanks, what’s the case number?

@AlexandreT-unity The case number is 1330494.

A fix for this has landed in 2021.2.0a14 and will be in preview 15.

Are there any news on when will preview 15 be available?

By the end of June, unless something goes wrong.