Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Bug IndexOutOfRangeException: Index was outside the bounds of the array.

Discussion in 'UGUI & TextMesh Pro' started by OvrBtn, Aug 6, 2022.

  1. OvrBtn

    OvrBtn

    Joined:
    Mar 26, 2021
    Posts:
    2
    Hello, so I'm getting error from TMP text input in Unity 2021.3.4f1, TMP version 3.0.6:

    IndexOutOfRangeException: Index was outside the bounds of the array.
    TMPro.TMP_InputField.GenerateHightlight (UnityEngine.UI.VertexHelper vbo, UnityEngine.Vector2 roundingOffset) (at Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMP_InputField.cs:3741)
    TMPro.TMP_InputField.OnFillVBO (UnityEngine.Mesh vbo) (at Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMP_InputField.cs:3568)
    TMPro.TMP_InputField.UpdateGeometry () (at Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMP_InputField.cs:3504)
    TMPro.TMP_InputField.Rebuild (UnityEngine.UI.CanvasUpdate update) (at Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMP_InputField.cs:3479)
    UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/CanvasUpdateRegistry.cs:215)
    UnityEngine.Canvas:SendWillRenderCanvases()

    I checked it in debugger and m_CaretSelectPosition from line 3741 is equal to 0 so when trying to get element of index [m_CaretSelectPosition - 1] it's getting outside the bounds. Is there any solution to fix it?

    EDIT: It seems like I managed to fix this problem by myself. It seems like this bug was coming from another bug in my code that was creating input field outside of canvas.
     
    Last edited: Aug 6, 2022
    Tudor and Wiechciu like this.