TMP InputField OnSubmit Event Bug

Unity Version:

Unity 6000.0.38

Platform:

Tested on Windows (PC build, Editor)
This issue does not occur on Android (AOS).

Issue Description:


    public void SendChat(string input)
    {
        if (string.IsNullOrEmpty(input))
            return;

        // send chat

        m_InputField.text = string.Empty;
        m_InputField.ActivateInputField();
    }

When using a TMP_InputField with an IME (Korean, Japanese, Chinese input methods), the onSubmit() event does not include the final composing character in the submitted text. Instead, the last composing character remains in the input field.

For example, typing โ€œ์œผ์•™๋งˆ์šฐ์•„์š”โ€ and pressing Enter results in:

  • onSubmit(string text) receiving โ€œ์œผ์•™๋งˆ์šฐ์•„โ€
  • The last character โ€œ์š”โ€ remains in the input field instead of being included in the submitted text.

This happens because compositionString is not finalized before the submit event fires. The onSubmit() callback receives only the fully committed text, excluding any remaining composition characters.

Steps to Reproduce:

  1. Create a TMP_InputField and attach an onSubmit listener.
  2. Type Korean text using an IME, ensuring that the last character is still being composed.
  3. Press Enter to submit the text.
  4. Observe that the last composing character is missing from the submitted string but remains in the input field.

This behavior differs from previous Unity versions(2022.3.31).

Of course, it is possible to manually append compositionString to the message when the onSubmit event fires. However, this does not seem like a proper solution.

Is there any mode setting or TMP configuration that I might have overlooked to control this behavior? Any advice would be appreciated!

1 Like

maybe unity 6000.0.38 broke how tmp_inputfield handles ime input, submit fires before compositionString finalizes, so last char gets left behind

try (I didnโ€™t test any of them):

a) force commit before clearing

{
    if (string.IsNullOrEmpty(input)) return;

    m_InputField.text += Input.compositionString; // commit last char

    // send chat

    m_InputField.text = string.Empty;
    m_InputField.ActivateInputField();
}

b)wait for composition to finish

private IEnumerator EnsureCompositionFinalized(string input)
{
    while (!string.IsNullOrEmpty(Input.compositionString))
        yield return null; // wait till ime done

    // send chat
    m_InputField.text = string.Empty;
    m_InputField.ActivateInputField();
}
public void SendChat(string input)
{
    if (string.IsNullOrEmpty(input)) return;
    StartCoroutine(EnsureCompositionFinalized(input));
}

c) use onEndEdit instead of onSubmit
m_InputField.onEndEdit.AddListener((input) => SendChat(input));
wonโ€™t fire exactly on enter but might be acceptable if nothing works

1 Like

Yes, using a Coroutine gives me the desired result. However, it would be best if Unity fixes this issueโ€ฆ :cry:

1 Like

good to know. also would be best if you submit a bug report