Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Bug NullReferenceException at TMPro.TMP_InputField.SendTouchScreenKeyboardStatusChanged

Discussion in 'UGUI & TextMesh Pro' started by Savidiy, May 14, 2021.

  1. Savidiy

    Savidiy

    Joined:
    Oct 16, 2016
    Posts:
    7
    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:
    upload_2021-5-14_14-44-50.png
     

    Attached Files:

    Last edited: May 14, 2021
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    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.
     
  3. Savidiy

    Savidiy

    Joined:
    Oct 16, 2016
    Posts:
    7
    I get this error on Unity 2020.3.6 with the TMP package for 3.0.4 and 3.0.6 version
     
    Last edited: May 14, 2021
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Downloading your project to take a closer look.

    Do you have steps to reproduce?
     
  5. Savidiy

    Savidiy

    Joined:
    Oct 16, 2016
    Posts:
    7
    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
     
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    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.
     
  7. Savidiy

    Savidiy

    Joined:
    Oct 16, 2016
    Posts:
    7
    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.
    upload_2021-5-15_13-49-58.png
     
  8. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    I added the "else if" as well as changed the order of the OnSubmit() so that it comes after SendTouchScreenKeyboardStatusChanged()

    Code (csharp):
    1.  
    2. if (m_SoftKeyboard == null || m_SoftKeyboard.status != TouchScreenKeyboard.Status.Visible)
    3. {
    4.     if (m_SoftKeyboard != null)
    5.     {
    6.         if (!m_ReadOnly)
    7.             text = m_SoftKeyboard.text;
    8.        
    9.         switch (m_SoftKeyboard.status)
    10.         {
    11.              case TouchScreenKeyboard.Status.LostFocus:
    12.              SendTouchScreenKeyboardStatusChanged();
    13.              break;
    14.         case TouchScreenKeyboard.Status.Canceled:
    15.              m_ReleaseSelection = true;
    16.              m_WasCanceled = true;
    17.              SendTouchScreenKeyboardStatusChanged();
    18.              break;
    19.         case TouchScreenKeyboard.Status.Done:
    20.              m_ReleaseSelection = true;
    21.              SendTouchScreenKeyboardStatusChanged();
    22.              OnSubmit(null);
    23.              break;
    24.         }
    25.     }
    26.  
    27.     OnDeselect(null);
    28.     return;
    29. }
    30.  
    Let me know if that makes more sense?
     
    Last edited: May 18, 2021
    kyubuns and Savidiy like this.
  9. Savidiy

    Savidiy

    Joined:
    Oct 16, 2016
    Posts:
    7
    Thank you for the changes. When will this be available in Package Manager?
     
  10. NineKech

    NineKech

    Joined:
    Nov 28, 2021
    Posts:
    1
    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
     
  11. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    302
    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
     
  12. bfaliuperspectives

    bfaliuperspectives

    Joined:
    Feb 10, 2021
    Posts:
    13
    Still got the issue with TMPro 3.0.6 and Unity 2021.3.26
     
  13. j1mmie

    j1mmie

    Joined:
    Oct 31, 2013
    Posts:
    34
    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: https://forum.unity.com/threads/3-2-0-pre-4-release-now-available.1376289/

    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.
     
  14. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,032
    Null exception on OnSubmit() issue is still there.
    Package 3.2.0-pre.5 or Unity 2023.2.0b1.
     
  15. thiagolrosa

    thiagolrosa

    Joined:
    Feb 22, 2017
    Posts:
    60
    I'm also having the same issue!
     
  16. chrismarch

    chrismarch

    Joined:
    Jul 24, 2013
    Posts:
    473