Author Topic: UIKeyNavigation erratic behaviour (registering too many key presses?)  (Read 4960 times)

stilghar

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Hi!

I already asked this directly on the UIKeyNavigation documentation thread but I will add it here in case it gets more visibility and can help others.

I'm having a weird issue with key navigation. I have 4 buttons, the menu works fine with mouse. Now that I added UIKeyNavigation to them I can select them also with keyboard. All fine until here. But the input seems to be too sensitive as I get erratic behaviour. Only if I press (and depress) the keys really, really fast I get the correct behaviour. Otherwise the focus changes to a random button (sometimes even the same one that was already on focus). It looks as if registering many key presses when only doing it once.

Any ideas?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
UIKeyNavigation is driven by UICamera's events, which reacts to Input.GetKeyDown, which occurs only once per frame. UICamera receives the GetKeyDown and then notifies the UIKeyNavigation, which then reacts accordingly by selecting another object. What are you seeing that's different and what version of NGUI are you using?

I just did a quick test to make sure -- added a button, put UIKeyNavigation on it, then duplicated it a few times. Navigation works as expected.

stilghar

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
I'm in the last NGUI version (just updated yesterday). It may be worth mentioning that I updated from NGUI 2.7...

Unity version 4.3.4.

Not in my dev computer at the moment, will try tonight with a clean scene. Maybe something in the upgrade process is messing things up.

stilghar

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Ok, solved one issue found another one.

My problem was that the input axis had gravity set to 10 and that seems to break the UIKeyNavigation system.

Now, I have another problem. When I change to another panel the focus is correctly given to a button I have there using the "Select on Click". But when I want to return to the main panel and I do the same with the button there (i.e. I "Select on Click" one button of the main panel) the button in the main panel doesn't regain focus for some reason. Any tips on what may be wrong?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
You need to have the game object enabled before you transfer selection to it.