Hello !
We use TMPro for a while now and we were in 1.3.0 and we updated to 1.4.1 but now some fields doesn’t work in our project.
We have a custom validator to remove emoji from our field with the following Validate method :
using System;
using TMPro;
using UnityEngine;
[Serializable]
public class NoEmojiValidator : TMP_InputValidator
{
private TMP_InputField InputField { get; set; }
private int m_startSelectIndex = 0;
private int m_endSelectIndex = 0;
private bool IsSelected { get { return m_startSelectIndex != m_endSelectIndex; } }
public void Init(TMP_InputField inputField)
{
InputField = inputField;
InputField.onTextSelection.AddListener(OnTextSelection);
InputField.onEndTextSelection.AddListener(OnEndTextSelection);
}
private void OnDestroy()
{
InputField.onTextSelection.RemoveListener(OnTextSelection);
InputField.onEndTextSelection.RemoveListener(OnEndTextSelection);
}
private void OnTextSelection(string text, int startSelectionIndex, int endSelectionIndex)
{
m_startSelectIndex = startSelectionIndex;
m_endSelectIndex = endSelectionIndex;
}
private void OnEndTextSelection(string s, int startSelectionIndex, int endSelectionIndex)
{
m_startSelectIndex = startSelectionIndex;
m_endSelectIndex = endSelectionIndex;
}
public override char Validate(ref string text, ref int pos, char ch)
{
if ((int)ch >= 55357)
{
return '\0';
}
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL
if (IsSelected)
{
int minIndex = Mathf.Min(m_startSelectIndex, m_endSelectIndex);
int maxIndex = Mathf.Max(m_startSelectIndex, m_endSelectIndex);
int length = maxIndex - minIndex;
text = text.Remove(minIndex, length);
text = text.Insert(minIndex, ch.ToString());
}
else
{
text = text.Insert(pos, ch.ToString());
}
#endif
pos += 1;
return ch;
}
}
I think our issue come from here cause when we use any other “Character Validation” all is fine. But as soon as we use this particular validator it fails whereas it was ok before.
I continue to search where is the problem but if you have any hint or if it’s a bug from your side, thanks in advance to answer
P.S : This is our issue =>
IndexOutOfRangeException: Index was outside the bounds of the array.
TMPro.TMP_InputField.GenerateCaret (UnityEngine.UI.VertexHelper vbo, UnityEngine.Vector2 roundingOffset) (at Library/PackageCache/com.unity.textmeshpro@1.4.1/Scripts/Runtime/TMP_InputField.cs:3313)
TMPro.TMP_InputField.OnFillVBO (UnityEngine.Mesh vbo) (at Library/PackageCache/com.unity.textmeshpro@1.4.1/Scripts/Runtime/TMP_InputField.cs:3281)
TMPro.TMP_InputField.UpdateGeometry () (at Library/PackageCache/com.unity.textmeshpro@1.4.1/Scripts/Runtime/TMP_InputField.cs:3219)
TMPro.TMP_InputField.Rebuild (UnityEngine.UI.CanvasUpdate update) (at Library/PackageCache/com.unity.textmeshpro@1.4.1/Scripts/Runtime/TMP_InputField.cs:3194)
UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/CanvasUpdateRegistry.cs:198)
UnityEngine.Canvas:SendWillRenderCanvases()
I can see in that case your “caretPositionInternal” has a bad value : -1
I am currently looking at the case and it appears there is an extra null character that is causing the issue with your custom validator.
QA has already replied to the case and suggested a code change which will allow you to get around the reported issue which is to simply check for char(0).
I’ll take a close look on my end to figure out what is going on with this null character.
I was able to identify the source of the Null character being forwarded to the Validate method.
This behavior will be as it was in version 1.3.0 of the TMP package. The solution for this issue will be in the next release of the TMP package which is expected to be version 1.4.2 for Unity 2018.3 or newer and version 2.0.2 for Unity 2019.x.
Until the next package is available, just filter out the Null character as per the QA’s suggestion.
@Stephan_B I was maybe too enthusiastic cause it seems it don’t work on mobile devices.
All our custom validator using the one mentionned above doesn’t take any input on mobile. So We can see the input action (the field enter in a selected state) but the native mobile keyboard never shows up.
Everything is fine on Standalone and Editor probably due to the no-keyboard.
I try to investigate further… but it’s quite a major issue for us ^^"
I think the case 1172102 must (still open) must be enough to repro this issue
But I can submit again exactly the same with default target platform to android or iOS
Actually reflecting on this last night as I went to sleep, I realized this was related to the following:
In the TMP_InputField.cs at line 3717, make the following changes
// Replace the following line with the line below
if (shouldHideSoftKeyboard == false && m_ReadOnly == false && contentType != ContentType.Custom)
// New line should be
if (shouldHideSoftKeyboard == false && m_ReadOnly == false)
Thank you! Dumb question but where is the TMP_InputField.cs script? I can’t find it in the “TextMesh Pro” folder in my project “Assets” folder. Definitely imported TMP into my project with no problem.