Text Input Confirmation on Mobile Keyboard

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
michaelheiml
Posts: 46
Joined: Thu Nov 08, 2018 5:47 am

Text Input Confirmation on Mobile Keyboard

Post by michaelheiml »

Hi Tony,

Goal: I want the player to input a number and then use this number to branch the dialogue. Everything works fine (Sequence, save number as variable, show value during following dialogues) *in the Editor as I can press Enter to confirm my input*.

Problem: I cannot find a way how to confirm the input on mobile which is my games' primary platform. I set it up so they virtual keyboard is shown on mobile (Android 11) when the Sequence is started (TextInput(..)). The keyboard pops up and I can enter a number, but pressing the keyboards' checkmark or the OK button only closes the keyboard (StandardUIInputField.cs/AcceptTextInput() is not called) - the Input Field is still shown, I can tap it again to bring up the keyboard again but nothing else. If I set Continue Button Mode to anything else than Never, tapping somewhere on the screen would continue the dialogue, but does then not store the entered value into the variable, and therefore the branching afterwards does not work (variable is always 0). Setting Continue Button Mode to Never leads to the problem above that I cannot "accept the text input". I also tried calling AcceptTextInput via the InputField Inspector event "OnEndEdit" but this also only works when Continue Button Mode != Never (which will lead to variable not stored).

What am I doing wrong here? I use prefab Standard Dialogue UI along with TextMeshPro.

Thanks, Michael
Last edited by michaelheiml on Thu Dec 09, 2021 8:18 am, edited 1 time in total.
michaelheiml
Posts: 46
Joined: Thu Nov 08, 2018 5:47 am

Re: Text Input Confirmation on Mobile Keyboard

Post by michaelheiml »

I figured it out by myself I think.

I need to insert an empty "delay" node with sequence "Continue()" between the node with the InputField sequence and the node where I access the variable as described somewhere in the docs (cannot find that again, maybe reference to this in the section about Input Fields).

Is that ok like that or do you suggest to use a different approach?

UPDATE 1
======
No that was too fast. It did workaround the problem but not really solve it. Because 2 other problems came up with this workaround:

1) now the Input does not work on Editor (only with pressing Return; not with pressing somewhere for Continue)
2) my workaround would require to use the Event OnEndEdit on TMP_InputField to call AcceptTextInput() on TextFieldUI - which I don't think this is the intended way to make the Input work on Mobile?

UPDATE 2
======
I also realized that enabling "Show Touch Screen Keyboard" on StandardUIInputField.cs leads to wrong behaviour (complete keyboard is shown instead of int/number only + pressing checkmark does not write the input value to the variable), while disabling this option gives me the proper input keyboard on mobile (the one I choose in TMP_InputField, in this case I want to enter an integer - therefore I choose Number Pad + Integer Validation) + pressing checkmark writes the input to the variable.

UPDATE 3
======
I tried several different configurations now but with no success to achieve exactly what I aim for. I came to realize it might be best if I describe that more precisely instead of posting issues I am facing, so what I want is:
- Have a TMP Input Field on mobile that stores the input in a variable and uses the variable in the next line to branch the dialogue (basically if input=3 go to branch1, if !=3 go to branch2)
- Have a number input keyboard pop up on mobile screen as soon as the user input is required
- Have the entered digit be stored into the variable when either the player presses the checkmark on the virtual keyboard OR when the player presses somewhere in the still-visible scene OR when the player presses a checkmark button on screen next to the input field (+ accepting the input on Editor/Mac/Win when pressing Enter)
- Have the continue button mode set to optional
Last edited by michaelheiml on Thu Dec 09, 2021 8:17 am, edited 1 time in total.
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Text Input Confirmation on Mobile Keyboard

Post by Tony Li »

Hi Michael,

Please import this patch:

DS_InputFieldPatch_2021-12-09.unitypackage

It will make the next step much shorter.

Then make a subclass of StandardUIInputField that overrides the ShowTouchScreenKeyboard() method:

Code: Select all

public class NumberInputField : StandardUIInputField
{
    protected override void ShowTouchScreenKeyboard()
    {
        m_touchScreenKeyboard = TouchScreenKeyboard.Open(inputField.text,  TouchScreenKeyboardType.NumberPad); 
    }
}
Duplicate your dialogue UI's Text Field UI -- for example, call it Number Field UI -- and replace the StandardUIInputField component with NumberInputField.

Finally, add an "Accept" UI Button inside your Number Field UI. Configure its OnClick() event to call the NumInputField component's AcceptTextInput() method.

In your TextInput() sequencer command, use Number Field UI instead of Text Field UI.
michaelheiml
Posts: 46
Joined: Thu Nov 08, 2018 5:47 am

Re: Text Input Confirmation on Mobile Keyboard

Post by michaelheiml »

Hi Tony,

thanks, I did what you suggested but with limited success, could you please help me:

1) If I only go through your suggested steps, I can use the UGUI Button to confirm input, but the virtual keyboards' "ok" button does only close the keyboard but not confirm the input (I assume though that most people would expect this to be enough to confirm input and continue dialogue). > To fix this I also need to wire the InputFields Event "OnEndEdit" to point at NumberInputField.AcceptTextInput

2) When doing this, the virtual keyboards' OK button works. But this leads to another problem - clicking on the UGUI button while the virtual keyboard is open does not work (what works would be double-tapping the unity scene, this closes the virtual keyboard first and then I need to press the UGUI button again to confirm input => unintuitive because all in all 3 taps).

Important to mention here, I have disabled the Continue Button before the Input sequence and restored it in the line after the input sequence with the sequencer commands:
SetContinueMode(false);
SetContinueMode(original);

Reason: if I leave the continue button enabled (optional), I can close the virtual keyboard by tapping once into the scene, but if I then tap somewhere on the screen again (not on the UGUI button), the dialogue continues but does not incorporate the entered value (the variable is not stored) => very confusing.

-> so all in all, right now I cannot give the user the choice to either confirm the answer with either one tap on the keyboards' "ok" button or on the UGUI button, which is basically what I want. I added a screenshot to clarify this a bit more.

3) Side question, since you sent me a patch but I regularly update to the latest DSFU, I might loose/overwrite the patch. Is there any other way to stay with vanilla DSFU?
Attachments
input field problem.jpg
input field problem.jpg (466.06 KiB) Viewed 2587 times
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Text Input Confirmation on Mobile Keyboard

Post by Tony Li »

Hi,

The change in the patch will be in the next vanilla release. Don't worry; I never make one-off patches that can be overwritten by a new release.

What if you get rid of the UI Button and use only the virtual keyboard's "ok" button to close and confirm input (by pointing it to AcceptTextInput)?

Alternatively, you could make the UI Button invisible and make it cover the whole screen. Then when user taps anywhere other than the keyboard, it should also call AcceptTextInput.
michaelheiml
Posts: 46
Joined: Thu Nov 08, 2018 5:47 am

Re: Text Input Confirmation on Mobile Keyboard

Post by michaelheiml »

Thanks Tony, yes that is a good suggestion!
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Text Input Confirmation on Mobile Keyboard

Post by Tony Li »

Glad to help! If you run into any snags and have questions, let me know.
Post Reply