Null Reference at TMPro.TMP_InputField.LateUpdate when deselecting an InputField on Android

08-22 17:59:07.438: E/Unity(11229): NullReferenceException: Object reference not set to an instance of an object at TMPro.TMP_InputField.LateUpdate () [0x00374] in :0

I get this error, when the InputField is currently selected and I call the Select() method on a button (to close the keyboard). Doesn’t happen in the Editor but on Android devices.

See the following thread and potential change to see if that resolves the issue you are running into?

I don’t think it’s the same issue. I don’t get the null reference from my script but it happens in Textmesh Pro itself. I only select a button and otherwise don’t do anything with the inputfield, so I can’t check for null pointers on my side.

The error happens in TMP_InputField.cs on line 1617:

            if (m_SoftKeyboard.status != TouchScreenKeyboard.Status.Visible)
            {
                if (m_SoftKeyboard.status == TouchScreenKeyboard.Status.Canceled)
                    m_WasCanceled = true;

                OnDeselect(null);
            }

Probably the TouchScreenKeyboard was closed by the button selection (which is what I was going for) and is now null

Can anybody confirm this?

I would need to be able to reproduce the behavior to understand why this error occurs at that particular line given there is already a null check for m_SoftKeyboard in that same function above.

Are you able to reliably reproduce this error? Can you provide me with a repro case or bug report?

I’ve provided a bug report with a sample project: http://fogbugz.unity3d.com/default.asp?1273631_hahuc5n9ue6pc0ff

It’s just a method that gets called on “OnValueChange” from the input field and if the input fields length is above 5 letters it selects a button. That triggers the Null Reference on my LG7 ThinQ.

Thank you for submitting the bug report.

I will try taking a look tomorrow or over the weekend and follow up with you as soon as I have more information.

1 Like

I was able to take a closer look at the bug report you submitted and have identified the source of the issue.

The fix is trivial and as follows:

I didn’t want to suggest adding a null check for m_SoftKeyboard until first understanding why it could be null given its state is already in this same function.

As it turns out, the value changed event is called after the initial null check on m_SoftKeyboard where it ends up null as a result of the deselection of the input field in your validation code.

Nice! :slight_smile:

I’m getting the same error. Given that this is a year (and a few TMP updates) later, I guess it must be something different.

This is what i get:

NullReferenceException: Object reference not set to an instance of an object.
at TMPro.TMP_InputField.SendTouchScreenKeyboardStatusChanged()
at TMPro.TMP_InputField.LateUpdate()

I use the InputField for the chat function in my app. It goes fine 99% of the time, but now and then i get this error. The last time i got the error (a few minutes ago), i think the app was doing a rebuild/refresh of the chat page while i was typing, but i’m not 100% sure of this.

@Stephan_B : Any pointer to what may be causing this and how i can solve it?

I’m using TMPro 3.0.6 and Unity 2020.3.13f.

Please let me know if you need more information. Thanks!

EDIT: I just noticed in the catlog that right before the error, there was a Debug.Log() message from my app saying that the app had just come back into focus (OnApplicationFocus) → hence, it seems that the keyboard was no longer on the screen when the error occurred (… but perhaps this was already obvious to you :))

EDIT2: Ugh, now i had another one, but this time right before the application came back in focus, so the keyboard must still have been on the screen

For those of you having the same problem, the following should probably work as a temporary fix:

  1. Move the TMPro folder (com.unity.textmeshpro@3.0.6) from the Package cache folder (ProjectName\Library\PackageCache) to your package folder (ProjectName\Packages)

  2. Enable write permission on the files in this folder

  3. Make the following change in TMP_InputField.cs:

(The moving is necessary because otherwise package manager will automatically change it back to the code of the official release)

The above null check will be included in the next release of the TMP package.

Also receiving tons of these errors in my error log from players after upgrading from 2019 to 2020 and after upgrading to TextMeshPro 3.0.6. Any idea when the next release will be that fixes this issue?

3.2.0-pre.2 was released this week. This preview package should be visible in Package Manager when enabling seeing preview packages in 2020.x.

Ok, thanks for the post.

Unfortunately though, it looks like upgrading to that version of TextMeshPro screws my textfields up. Here is an example below:

Attached images of same textfields using 3.0.6 and 3.2.0-pre.2 are attached. Note, pre.1 has the same issue.


Did you update the TMP Essential Resources after switching to Preview 1 & 2 as per the Upgrade Note?

In preview 1, the shaders were updated for compatibility reasons with SRP where using the previous shader (from 3.0.6) in Preview 1 or 2 would result in the white blocks as seen in your image.

Ah, I guess I shoulda read that. Thanks, it works now!

1 Like

had the same problem. updated the tmpro but now there is another error message.

NullReferenceException: Object reference not set to an instance of an object. TMPro.TMP_InputField.OnSubmit (UnityEngine.EventSystems.BaseEventData eventData) (at <00000000000000000000000000000000>:0) TMPro.TMP_InputField.LateUpdate () (at <00000000000000000000000000000000>:0)

turns out eventData is null. need to add another null check
Edit:

public virtual void OnSubmit(BaseEventData eventData)
        {
            if (!IsActive() || !IsInteractable())
                return;

            if (!isFocused)
                m_ShouldActivateNextUpdate = true;

            SendOnSubmit();
            DeactivateInputField();
            eventData?.Use();
        }
1 Like

This validation fixed this problem, PLEASE, update the TMPro.

NullReferenceException: Object reference not set to an instance of an object.

TMPro.TMP_InputField.OnSubmit (UnityEngine.EventSystems.BaseEventData eventData) (at <00000000000000000000000000000000>:0)