Author Topic: UIDragObject problem: multi drag on the same object  (Read 5132 times)

Ernest

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 40
    • View Profile
UIDragObject problem: multi drag on the same object
« on: September 04, 2013, 07:34:46 AM »
Hi,

I got a weird issue when i'm dragging the same object with 2 fingers (android tablet), it splits in two objects on the screen... (it display below the moving finger). Actually, I notice that the UIDragObject.target (so the transform of the object i wanna drag) is constantly swapped between my 2 fingers! (his value changes) So I don't really know how the target it set in NGUI (read the code don't help), but i guess a raycast is done for each finger on the press event, and how both collide with the object, the target is related to both the fingers...

Please help me on that!

Ernest

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 40
    • View Profile
Re: UIDragObject problem: multi drag on the same object
« Reply #1 on: September 05, 2013, 05:04:20 AM »
UP (please)  :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDragObject problem: multi drag on the same object
« Reply #2 on: September 05, 2013, 05:17:30 AM »
Each finger is treated separately, so I'm guessing you are triggering your drag logic twice. Record the fact that you're dragging, and ignore the next press.

Ernest

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 40
    • View Profile
Re: UIDragObject problem: multi drag on the same object
« Reply #3 on: September 05, 2013, 07:38:15 AM »
Well, i'm sure i do everything right on that point (i thought about that in a first place)... First i done my own sprites pool (to handle multi-touch) for some specific behaviour, it stockes in a dictionary the gameobjects i'm dragging and i ensure that i can't have the same object in the dictionary twice; furthermore i set a flag in my OnPress event as you said, that allows to add a GO in the dictionary only when the flag is set to false... How can it get wrong!

EDIT: i tested with a simple scene and a drag object already setted on a gameobject, and indeed it works... But i don't get it, how can the target be setted twice anyway?!
   
« Last Edit: September 05, 2013, 10:47:32 AM by Ernest »

Ernest

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 40
    • View Profile
Re: UIDragObject problem: multi drag on the same object
« Reply #4 on: September 06, 2013, 11:59:57 AM »
Forget the edit, i retested with a coworker of mine in a new scene and just a gameObject with a UIDragObject on it and the bug still happens. So touch the object with two fingers and drag in two different directions, the sprite is duplicated and blink below both your fingers...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDragObject problem: multi drag on the same object
« Reply #5 on: September 07, 2013, 12:04:33 AM »
Replace the file with this version and it will work as expected.

Ernest

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 40
    • View Profile
Re: UIDragObject problem: multi drag on the same object
« Reply #6 on: September 10, 2013, 03:48:31 AM »
Thanks for the support but, I tested with the new file; and i still get the same issue...

Ernest

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 40
    • View Profile
Re: UIDragObject problem: multi drag on the same object
« Reply #7 on: September 11, 2013, 02:55:46 AM »
UP

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDragObject problem: multi drag on the same object
« Reply #8 on: September 11, 2013, 07:53:41 AM »
Inside the OnDrag function, change the first "if" statement to:
  1. if (mPressed && mTouchID == UICamera.currentTouchID && enabled && NGUITools.GetActive(gameObject) && target != null)
See if that fixes your issue.

Ernest

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 40
    • View Profile
Re: UIDragObject problem: multi drag on the same object
« Reply #9 on: September 12, 2013, 04:51:19 AM »
Ok, this fix the duplication problem, BUT this generates an other issue...  >:( Now when you drag your sprite (on a tablet device mostly) with a certain speed, there is a lag between your finger and the sprite (depending of the drag speed)! So please, how this becoming a major problem (for me as for you i guess) could you take the time to really test it on a tablet device and fix these problems once for all? Thanks for your answers anyways  :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDragObject problem: multi drag on the same object
« Reply #10 on: September 12, 2013, 08:10:07 AM »
There is always going to be lag behind the touch and the object -- it depends on your framerate and has nothing to do with the if check I added.

Ernest

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 40
    • View Profile
Re: UIDragObject problem: multi drag on the same object
« Reply #11 on: September 12, 2013, 09:02:05 AM »
Again, do the test by yourself! I tested the old version => no lag (or quasi invisible), and with the new => a lag of about 100px with a high speed drag...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDragObject problem: multi drag on the same object
« Reply #12 on: September 13, 2013, 10:41:16 AM »
I did. There is no difference between "before" and "after". Do I need to record a video to prove it?

Think about it logically. What does adding a single integer equality check have to do with lag? Check your framerate in the older build and in the current. Chances are, there is a difference -- and that's what's causing your visible lag.

Ernest

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 40
    • View Profile
Re: UIDragObject problem: multi drag on the same object
« Reply #13 on: September 16, 2013, 02:57:34 AM »
Oh, when I said "the older version", i meant before all this drag problem correction (so not only the if statement but before the new UIDragObject file you gave to me)... I think the booleans added and the multiple attributions and comparaisons you're doing, could cause a delay on the drag.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIDragObject problem: multi drag on the same object
« Reply #14 on: September 16, 2013, 02:16:33 PM »
A pair of comparisons are not going to cause any kind of lag. In any case, just to humor you I tried the before changes vs after changes test. Predictably, everything behaves identically (aside from the changes fixing the multi-finger dragging issues).