Input Field not getting selected?
Hello there!
I currently have a prefab called HighScoreTemplate, it has a script on it called HighScoreTemplate.cs
This script has a AcceptInput() function that sets the input field to be interactable, this part works great because I am able to tap on the input field to enter text.
public void AcceptInput()
{
NameField.interactable = true;
}
However, I want to be able to enter text into the field immediately without having to tap on it first.
Therefore I created a Select() function in the HighScoreTemplate.cs script that will call .Select() on the input field and then .ActivateInputField() afterwards.
public void Select()
{
// Select it
NameField.Select();
NameField.ActivateInputField();
}
However, this wasn't automatically selecting the NameField input field, as the keyboard did not pop up on my Android device.
I have verified through debugging that this Select() function is being called and run.
I assumed that maybe Unity had a delay, so I attempted this test to see if it would work:
int counter = 1;
while(counter <= 50 && !_newHighScoreTemplate.NameField.isFocused)
{
_newHighScoreTemplate.Select();
Debug.Log("Select Attempt #" + counter);
counter++;
}
This test gave me the same result, the android keyboard did not pop up and allow me to input text into the input field.