Author Topic: Bug Report: UIDragObject bug when disabling/enabling  (Read 4176 times)

Ana

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Bug Report: UIDragObject bug when disabling/enabling
« on: December 29, 2013, 09:14:05 AM »
I've run riecently into a bug and wanted to point it (and the fix) out in case anyone else runs into the same problem in the future.
I have an image that has UIDragObject attached and everything works great. However, I had a need to disable that script and then enable it again in the future.
When I enable it again, the last touch position the script registered is way different that the new touch position and that causes the script to offset the image by a great amount even though you just touched it and haven't really dragged it around.
It took me half an hour to get into it and figure what was causing the problem. A simple solution is to add this to the UIDragObject script:

  1. void OnDisable()
  2.     {
  3.         mStarted = false;
  4.     }
  5.  

That way first touch after the next enable will be treated as such, and the previously remembered touch will not be taken into account.

I'm not up to date with current NGUI so I don't know if it has been fixed, but I am pointing it out just in case it hasn't.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Bug Report: UIDragObject bug when disabling/enabling
« Reply #1 on: December 29, 2013, 06:36:43 PM »
Are you disabling the object while it's being dragged? I see no other way why this would not get set to 'false' for you in OnPress(false).

Ana

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: Bug Report: UIDragObject bug when disabling/enabling
« Reply #2 on: December 30, 2013, 04:28:48 AM »
No, not the object, I am disabling the script but for all intents and purposes it doesn't make a difference.
I am disabling the script when the user starts pinching so another non ngui script can do the pinch scaling. And then when the user stops pinching it is enabled again so the object can be dragged around. (this wouldn't be needed if NGUI had support for multitouch gestures, but it doesn't)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Bug Report: UIDragObject bug when disabling/enabling
« Reply #3 on: December 30, 2013, 01:10:03 PM »
Same thing though. Script gets disabled, so it has no way of receiving the OnPress(false) notification. I've added your change in 3.0.8 f2 btw.

Ana

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Re: Bug Report: UIDragObject bug when disabling/enabling
« Reply #4 on: December 30, 2013, 02:31:01 PM »
Quote
Same thing though. Script gets disabled, so it has no way of receiving the OnPress(false) notification.
That's why I said it doesn't make a difference.

Quote
I've added your change in 3.0.8 f2 btw.
Thank you.