Author Topic: UIKeyNavigation doesnt work with timescale=0 NGUI 3.9.6 Unity 5.3.1f1  (Read 11655 times)

unitydude

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 7
    • View Profile
Hi ,

I am trying to implement a pause menu and navigate between buttons but it does not work because I have Time.timeScale = 0f.

If i remove it works and I can work correctly in the pause menu.
Mouse clicks and hovers are working fine with time scale 0 .

I haven't tried this with a previous version so I dont know if this is specific to this version .

Is there a way I can ignore the time scale on the keyboard/controller events ?

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIKeyNavigation doesnt work with timescale=0 NGUI 3.9.6 Unity 5.3.1f1
« Reply #1 on: February 07, 2016, 12:07:39 AM »
Some things in Unity break when timeScale is at 0. Moving a collider doesn't update physics properly while the time scale is 0, so raycasts fail for example. Some other things also flat out break, like cloth in Unity 4. I don't recommend setting it to 0. Set it to a small value instead. I used Time.timeScale = 0.001f; in Windward, for example.

unitydude

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: UIKeyNavigation doesnt work with timescale=0 NGUI 3.9.6 Unity 5.3.1f1
« Reply #2 on: February 07, 2016, 02:32:56 AM »
Thanks for the reply,

I tried this with .001   --> pressing up/down will respond only after long press for a second or a bit longer and keeps cycling across all three buttons around 20 times
I tried with .01          -->  Pressing up/down will respond immediately but will cycle as above
I tried with .1            --> Pressing up/down will respond immediately but will cycle 3-5 times
I tried with 1             -->  Pressing up/down will respond immediately but it will cycle very fast showing like a flash

Note that I have a hover sprite to see when its selected

So I guess its not working at all for me   


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIKeyNavigation doesnt work with timescale=0 NGUI 3.9.6 Unity 5.3.1f1
« Reply #3 on: February 08, 2016, 01:30:01 AM »
Where are you trying this and what is your method of input? If you examine the code for UIKeyNavigation's OnNavigate function, you will see that it will check -- is the frame the same as before? If so, no navigation will occur. This means that only one event will be processed per frame. Now if you check UICamera.cs where OnNavigate is sent out you will see that it gets sent after checking UICamera.GetDirection. Looking inside that function you can see that it's using unscaled delta time inside (it's not affected by timeScale at all), and will only fire every 250 milliseconds at most -- 4 times per second while the direction is held.

So my question is, what are you doing to fire it more frequently?

unitydude

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: UIKeyNavigation doesnt work with timescale=0 NGUI 3.9.6 Unity 5.3.1f1
« Reply #4 on: February 08, 2016, 09:39:32 AM »
Thanks for the explanation , I put some Debug.Logs and found out that two things were causing this

1-The sensitivity rate in my input manager was 1000 which was causing the Notifies to  OnNavigate be sent 33 times.
 the reason I put at 1000 is because navigating between buttons took long press so I made it more sensitive which caused this

2-There were collides in the scene that had input key binding same as the arrows for control, I disabled them when the pause menu was shown

I fixed the long press by changing the GetAxis val check in the GetDirectoin in the UICamera to have the threshold at 0 not .75, this made the key responding instantaneously. What I noticed that the keyboard check in the UICamera doesn't work at all.

Problem solved thanks

computernerd92708

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: UIKeyNavigation doesnt work with timescale=0 NGUI 3.9.6 Unity 5.3.1f1
« Reply #5 on: February 16, 2016, 05:21:59 AM »
Thanks for the tips Aren.

I'm still having a few issues with this.  When I set the timeScale to 0.001f, keyboard axis input is still not recognized.

My second issue is that startsSelected does not work when using the Keyboard (and having the Mouse enabled in the camera event listener). I need this enabled in my Conversation dialog by default.

computernerd92708

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: UIKeyNavigation doesnt work with timescale=0 NGUI 3.9.6 Unity 5.3.1f1
« Reply #6 on: February 16, 2016, 05:24:00 AM »
Oh, this is with 3.9.7.

computernerd92708

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: UIKeyNavigation doesnt work with timescale=0 NGUI 3.9.6 Unity 5.3.1f1
« Reply #7 on: February 16, 2016, 06:02:19 AM »
Unitydude - great find on the threshold.  It appears that Unity scales the keyboard axis increments based on the timeScale, so it would take a VERY long time to reach 0.75f at a timeScale of 0.001f.

Keeping it at 0 for keyboard input makes the UI much more snappy and fun to use IMO.  You might want to make it default Aren, or user configurable.

The startsSelected issue is still outstanding.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIKeyNavigation doesnt work with timescale=0 NGUI 3.9.6 Unity 5.3.1f1
« Reply #8 on: February 18, 2016, 06:55:11 PM »
Hmm... When did the unity's input start getting affected by timeScale?

Starts selected won't work if you have mouse input enabled because mouse input effectively overwrites whatever you have selected by default.