Inside a panel, I have two input boxes and two buttons. On all the controls I added the "UI Key Navigation" script. I want the Username control to have focus when the game starts, so I set the "Starts Selected" option on the UIKeyNavigation script that is part of the Username TextBox.
However, when the game starts, it does not have focus.
Changing the code in UIKeyNavigation.cs from this:
void Start ()
{
#if UNITY_EDITOR
if (!Application.isPlaying) return;
#endif
mStarted = true;
if (startsSelected && isColliderEnabled)
UICamera.hoveredObject = gameObject;
}
To this:
void Start ()
{
#if UNITY_EDITOR
if (!Application.isPlaying) return;
#endif
mStarted = true;
//if (startsSelected && isColliderEnabled)
if (startsSelected)
{
UICamera.hoveredObject = gameObject;
UIInput inp = gameObject.GetComponent<UIInput>();
if (inp != null)
inp.isSelected = true;
}
}
Fixes my issue. Not sure why you are checking if the collider is enabled, so my solution may have an unforeseen side effect.