Author Topic: [Solved?] Buttons not responding after game loses and regains focus (And. Tab 2)  (Read 15769 times)

Moran

  • Guest
On an Android Galaxy Tab II, when my game is running and then loses focus (by pressing "Home", by pressing the power button to turn off the screen, by switching to another running app in the background, etc.) and then regains focus, NGUI buttons are not responding.

I saw a similar problem that used to happen with EZGUI, here: http://forum.unity3d.com/threads/100425-Strange-Behavior-after-Suspending-and-Resuming-Game, so I tried replacing all of NGUI's and ITween's realtimeSinceStartup with Time.time - didn't help.

I also tried implementing OnApplicationFocus that re-enables all colliders, and although the event was run in the Editor, it doesn't help on the tablet.

Any ideas?

EDIT: Also tried deltaTime instead of Time.time (no good), tried different android API versions and OpenGL versions and other various build settings - nothing.
EDIT2: Somewhat solved using this code, provided by @Nicki, to replace within UICamera.cs:
  1. public void ProcessTouches ()
  2.     {          
  3.         int firstTouchID = int.MaxValue;
  4.         for (int i = 0; i < Input.touchCount; i++)
  5.         {
  6.             firstTouchID = Mathf.Min(Input.GetTouch(i).fingerId, firstTouchID);
  7.         }
  8.        
  9.         for (int i = 0; i < Input.touchCount; ++i)
  10.         {
  11.             Touch input = Input.GetTouch(i);
  12.  
  13.             if (allowMultiTouch || input.fingerId == firstTouchID)
  14.             { (...)
More details in this thread: http://www.tasharen.com/forum/index.php?topic=2737 - Thanks @Nicki!
« Last Edit: February 13, 2013, 10:36:26 AM by Fnord »

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Try enabling multitouch in UICamera.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile

Moran

  • Guest
Try enabling multitouch in UICamera.

Multitouch was already enabled. I tried disabling it, but no change.

May be the same as http://www.tasharen.com/forum/index.php?topic=2737

The workaround code you provided there solved the problem (but generated a few new ones)! First of all, thanks a lot for that! If you have newer code that solves this problem with less impact on NGUI functionality, I would love to get it. Otherwise I'll check it out myself to see what can be done about the new issues (mainly graphical - missing buttons, wrong layers for some reason? I have to test it further)

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
I'm afraid I don't have any fancier fix for it, but I believe Aren fixed it in the NGUI trunk, so it should work in the newest version.

Moran

  • Guest
It's certainly fixed - After solving a problem with Unity Asset Store updating, I finally got the newest version and in the problem is gone.

Thanks Nicki and Aren!

NaxIonz

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 70
    • View Profile
What code do I need to grab from the latest NGUI release to solve this issue (I experience it on the Kindle devices)

Unfortunately, I can't upgrade all of NGUI because we need to stay in Unity 3.5 for ARMv6 reasons.

Would it be safe just to replace my old version of UICamera.cs with the latest one?
« Last Edit: July 17, 2013, 11:40:00 AM by NaxIonz »

NaxIonz

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 70
    • View Profile
Hmmm, replacing UICamera.cs doesn't seem to fix the issue I am having.

If I open an Amazon IAP dialog (native small pop-up that overlays on top of the game, covering about 1/3 of the screen) on the Kindle, cancel it, and open it again, cancel, open...etc after about 20 iterations, the UI is no longer taking any input. It's not frozen, I can see stuff animating and the system back button properly navigates backwards, its just that no UI is responsive.

(FWIW, the game is 100% UI done via NGUI)
« Last Edit: July 17, 2013, 06:15:25 PM by NaxIonz »

NaxIonz

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 70
    • View Profile
When I get into this state, my touch count is zero. I have a log message in the camera's update that gets called every 3 seconds, and that continues to log, but the log message I placed inside the for loop of the touch count stops getting called once I am in this state.

So somehow the touches are never getting registered to Unity's Input

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
What does not upgrading NGUI have to do with 3.5? The latest version of NGUI is fully compatible with Unity 3.5.7.

NaxIonz

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 70
    • View Profile
What does not upgrading NGUI have to do with 3.5? The latest version of NGUI is fully compatible with Unity 3.5.7.

Ahh, I miss-read the release notes. It says not to upgrade if you're 3.5.4 or lower. I suppose since we are on 3.5.7f6 it would be safe to get the latest NGUI ^_^

Is it possible that would fix the issue? I mean, the real problem I am having is that Input.touchCount is always zero once I get into this funky state.

EDIT/UPDATE:
Getting the latest NGUI code did not fix the issue :-(
Unity still is stuck at zero for Input.touchCount
« Last Edit: July 18, 2013, 01:22:28 PM by NaxIonz »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Input.touchCount comes straight from Unity, and is not NGUI's code. If it's zero, then you have a problem within Unity.

NaxIonz

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 70
    • View Profile
Input.touchCount comes straight from Unity, and is not NGUI's code. If it's zero, then you have a problem within Unity.

Do you know of anything I could do to resuscitate Unity's touch handler? I've posted over on Unity and StackOverflow, but haven't had any responses in the last week :-(

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
I have no idea, but considering that I am guessing only you are running into this issue (and I've never heard of it, and judging from the lack of responses -- neither have others), it's likely something on your end. What it is, I don't know.

NaxIonz

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 70
    • View Profile
I have no idea, but considering that I am guessing only you are running into this issue (and I've never heard of it, and judging from the lack of responses -- neither have others), it's likely something on your end. What it is, I don't know.

As an interesting experiment, I decided to broaden my test range on this issue. Instead of limiting it to my Amazon build on the Kindle Fire, I decided to put a regular Google Play build onto the Kindle. Issue occurred. Then I tried the game on my S3, and while it took a lot more task switching to repro it, it finally occurred. Then, for kicks and giggles, I tried another Unity game I had purchased months ago (Bladeslinger) on my ASUS Infinity tablet. Sure enough, initiating and canceling the IAP eventually put their game in a state that no longer accepted input, yet still responded to the system back button.

Long story, I guess this is just a Unity bug, and maybe a pre-4 bug, since this game was most likely made with Unity 3 given that it's been out for almost a year.