1

https://docs.unity3d.com/Packages/com.unity.textmeshpro@1.3/api/TMPro.TMP_InputField.html#TMPro_TMP_InputField_onSubmit

here is the onsubmit method, however this is not exposed in the editor, only onvaluechanged, onselect, onendedit, ondeselect are exposed.

enter image description here

I would be ok to use onendedit, however I use this inputfield for a chatbox and if the user presses ESCAPE to abort his chat, currently onendedit will still trigger and the message gets sent. I want something that is only triggered when the user pressed ENTER, and I guess this would be covered by onsubmit however its not being exposed in the inspector for some reason.

Any advice appreciated. Thanks.

user8810083
  • 599
  • 1
  • 5
  • 21

1 Answers1

3

You will have to add this with code. Heres a one line way to make stuff happen when they submit.

    Start()
    {
        GetComponent<TMP_InputField>().onSubmit.AddListener((string input)=>{DoThing();});
    }

Easier to understand version...

    public TMP_InputField MyInputfield

    Start()
    {
        MyInputfield.onSubmit.AddListener(DoStuffWhenSubmitted);
    }
    
    void DoStuffWhenSubmitted(string input)
    {
        // do stuff here
    }
Guye Incognito
  • 2,726
  • 6
  • 38
  • 72
  • 1
    Your bottom code won't compile because `DoStuffWhenSubmitted` needs a string parameter. `void DoStuffWhenSubmitted(string text)` – Daniel M Sep 07 '21 at 12:46