Author Topic: Missing Touch Events  (Read 5723 times)

whydoidoit

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Missing Touch Events
« on: June 28, 2012, 11:45:22 AM »
Hi - I'm getting a few problems with button presses when my frame rate drops on IOS due to extra network players arriving and configuring.  It's happening in the NGUI stuff and also elsewhere on my game.  I've been on to Unity Support and they've pointed out that Began events are not guaranteed to arrive in situations where the main loop doesn't run fast enough.

They're suggesting is that the Began event will be overwritten by a Moved or a Stationery before the game gets to see it.  I see UICamera uses Began - so I'm going to modify it to look for a moved etc on a finger not currently tracked and have that do the pressed action - just wondering if you had anything else that might already do this?


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Missing Touch Events
« Reply #1 on: June 29, 2012, 02:51:36 AM »
Began events? Moved? Stationary? What?

arihollander

  • Guest
Re: Missing Touch Events
« Reply #2 on: July 11, 2012, 01:59:02 PM »
I have no idea what "Began" events are, but I too am getting missed button presses in iOS.

Any ideas?

PhilipC

  • Guest
Re: Missing Touch Events
« Reply #3 on: July 11, 2012, 02:51:32 PM »
I do have 1 idea but i cant test on iOS (dont have any devices) so this is a wild guess so it may not be correct.

Line 787 of UICamera looks like
  1.  bool pressed = (input.phase == TouchPhase.Began);
now from what whydoidoit say Unity Support said to do you need to also look at TouchPhase.Stationary and TouchPhase.Moved. The trick here is to only count stationary and moved as pressed = true once (easier said then done). I think some value of currentTouch will need to be watched to see if you should included stationary and moved but unsure which (if any).

If i come up with something more concrete i will post.

reptilebeats

  • Guest
Re: Missing Touch Events
« Reply #4 on: July 11, 2012, 05:35:06 PM »
i havent had any problems with useing touch yet, but i dont use any scripts provided by ngui except from the panel, all my sprits are tested for hits from one script instead of sending a message

if i explain for people who dont know began events is the current touch of a finger on screen. so began is when the finger has began touching, stationary is when the finger is well it says it self. so in a script it may look like

var touch = Input.GetTouch;

if(touch.phase == TouchPhase.Began){
do something
}
and for multi touch just put into a loop to count each touch.


arihollander

  • Guest
Re: Missing Touch Events
« Reply #5 on: July 13, 2012, 12:42:48 PM »
I tried making these changes to UICamera.cs and it seems to work thus far:

I modified the MouseOrTouch class (changes in blue):

public class MouseOrTouch
   {
      public Vector2 pos;            // Current position of the mouse or touch event
      public Vector2 delta;         // Delta since last update
      public Vector2 totalDelta;      // Delta since the event started being tracked

      public Camera pressedCam;      // Camera that the OnPress(true) was fired with

      public GameObject current;      // The current game object under the touch or mouse
      public GameObject pressed;      // The last game object to receive OnPress

      public float clickTime = 0f;   // The last time a click event was sent out
      
      public bool isNew = true;       //Allow for the possibility that MouseOrTouch is late to the party and missed a Began event

      public ClickNotification clickNotification = ClickNotification.Always;
   }




And then I changed:

         bool pressed = (input.phase == TouchPhase.Began);
to:

         bool pressed = (currentTouch.isNew);
         currentTouch.isNew=false;


in ProcessTouches

Anyone think of any reason this will cause problems?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Missing Touch Events
« Reply #6 on: July 13, 2012, 02:14:23 PM »
Should be fine. I've added something very similar on my end, and you'll see it in the next release.

arihollander

  • Guest
Re: Missing Touch Events
« Reply #7 on: July 13, 2012, 06:19:41 PM »
Good Ghod: you have given me the illusion that I know what I am doing!

It is certain not to last.