NullReferenceException at TMPro.TMP_InputField.SendTouchScreenKeyboardStatusChanged

I get this error on Android 6.0 Meizu M5s, when I recieve “inputField.onSubmit” and hide “inputField.gameObject.SetActive(false)” in it.
I attach Unity project and apk, which represent this bug.
I think bug here:

7140260–853964–TextMeshProBug.zip (9.86 MB)

I know that a similar bug was reported a few months back. Please be sure to test with the latest release of whatever version of Unity you are using as well as the latest for TMP.

By latest, I mean if you are on Unity 2019.4, the latest is 2019.4.26f1 and the latest TMP package for 2019.4 is 2.1.6.

I get this error on Unity 2020.3.6 with the TMP package for 3.0.4 and 3.0.6 version

Downloading your project to take a closer look.

Do you have steps to reproduce?

I tried to make the example simple. Enter any text in the first field on your mobile device and click done/ok. The mobile keyboard should disappear, the input field should disappear and what gets into the log is displayed on the right. To return the input field, there is a “Restore” button. All the code is in sample.cs

Thank you for providing the repro project.

I was able to reproduce the issue which is simply related to the fact that OnSubmit() is called before
SendTouchScreenKeyboardStatusChanged() which in theory is fine. However, since you are disabling the input field in OnSubmit() this results in OnDisable() getting called which in turn calls DeactivateInputField() which then sets the soft keyboard to null.

It would seem that calling SendTouchScreenKeyboardStatusChanged() first and then OnSubmit() might be the appropriate change here but I am not entirely sure yet.

In my project, I try to work around this problem. Therefore, I tried to send data and hide inputField not to onSubmit, but to onTouchScreenKeyboardStatusChanged. Unfortunately, if you hide the input field in it, the Exception appears further in LateUpdate. In the picture, I showed the possible location of the error. I think “else if” is appropriate here.

I added the “else if” as well as changed the order of the OnSubmit() so that it comes after SendTouchScreenKeyboardStatusChanged()

if (m_SoftKeyboard == null || m_SoftKeyboard.status != TouchScreenKeyboard.Status.Visible)
{
    if (m_SoftKeyboard != null)
    {
        if (!m_ReadOnly)
            text = m_SoftKeyboard.text;
       
        switch (m_SoftKeyboard.status)
        {
             case TouchScreenKeyboard.Status.LostFocus:
             SendTouchScreenKeyboardStatusChanged();
             break;
        case TouchScreenKeyboard.Status.Canceled:
             m_ReleaseSelection = true;
             m_WasCanceled = true;
             SendTouchScreenKeyboardStatusChanged();
             break;
        case TouchScreenKeyboard.Status.Done:
             m_ReleaseSelection = true;
             SendTouchScreenKeyboardStatusChanged();
             OnSubmit(null);
             break;
        }
    }

    OnDeselect(null);
    return;
}

Let me know if that makes more sense?

2 Likes

Thank you for the changes. When will this be available in Package Manager?

Any updates on this issue? Because I am still having the same problem, I’ve noticed there were no new changes that I can find in the package manager

I just got this issue as well from user reports (not myself, not sure if it’s the exact same repro case, but same null error). Using TMPro 3.0.6. Is there coming a major version change soon or what’s causing the delay? @Stephan_B

Still got the issue with TMPro 3.0.6 and Unity 2021.3.26

This bug was fixed in all version of TextMeshPro after 3.0.6.

3.2.0-pre.4 for example, can be installed by following the instructions here: *** 3.2.0-pre.4 Release Now Available! ***

Namely:

  1. Click the + icon in package manager
  2. Click Add package by name
  3. For Name, use com.unity.textmeshpro
  4. For Version, use 3.2.0-pre.4

I did not try out the 4.x major revision because my version of Unity is too old, but I verified that its source code contains the fix.

Null exception on OnSubmit() issue is still there.
Package 3.2.0-pre.5 or Unity 2023.2.0b1.

3 Likes

I’m also having the same issue!

you can vote for this active bug to be fixed here:

1 Like