I have an Input Field on my scene (in this case a login screen) and would like to ensure that if the user selects a field, it removes the existing text by clearing the fields current value. The following code works, however it exhibits the following behaviour:
Stage this by having no starting value in InputField, and setting text property of Text child object to “Username”.
- Clear the text from the field.
- Since it is empty, show the value of text (i.e. “Username”).
- Focus gets set to the field.
- Clear the text from the field now that value is seen as “” and focus is in the field.
using UnityEngine;
using UnityEngine.UI;
public class EventHandler : MonoBehaviour
{
public void OnFocusUserName( GameObject userNameField )
{
InputField inputField = userNameField.GetComponentInChildren<InputField>( );
inputField.value = "";
}
}
My question is: How do I clear the text from a Input Field without having the default Text value flash by?
To save time - a workaround using this code is to set “Starting Value” and leave the text property of the child Text object empty. That means I’m actually setting a “value” however and is not the same scenario being described.
Basically I’d like to be able to clear the value from Input Field and not have any visual side effects from the “mask text”.