Author Topic: Possible Bug: Starts Selected does not appear to focus the control.  (Read 5404 times)

BrienKing

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
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:

  1.         void Start ()
  2.         {
  3. #if UNITY_EDITOR
  4.                 if (!Application.isPlaying) return;
  5. #endif
  6.                 mStarted = true;
  7.                 if (startsSelected && isColliderEnabled)
  8.                 UICamera.hoveredObject = gameObject;
  9.         }
  10.  
  11.  

To this:

  1.         void Start ()
  2.         {
  3. #if UNITY_EDITOR
  4.                 if (!Application.isPlaying) return;
  5. #endif
  6.                 mStarted = true;
  7.                 //if (startsSelected && isColliderEnabled)
  8.                 if (startsSelected)
  9.                 {
  10.                         UICamera.hoveredObject = gameObject;
  11.                         UIInput inp = gameObject.GetComponent<UIInput>();
  12.                         if (inp != null)
  13.                                 inp.isSelected = true;
  14.                 }
  15.         }
  16.  
  17.  

Fixes my issue.  Not sure why you are checking if the collider is enabled, so my solution may have an unforeseen side effect.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Possible Bug: Starts Selected does not appear to focus the control.
« Reply #1 on: October 07, 2015, 07:51:12 PM »
Highlighting will only work if your control scheme is set to Controller. So unless you explicitly unchecked everything but Controller on the UICamera, it will default to mouse control when you hit the Play button.

That modification should not be necessary, and the collider check is necessary. You basically made it possible to select objects that have no colliders -- objects that should not be interactable.