Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by EDevJogos · Dec 25, 2017 at 05:08 PM · androidtouchdrageventsystemui image

How to force Eventsystem Drag

So, i'm making a virtual joystick for my android game, the joystick anchor its position to where the user touches on the screen, and the whole process of moving the joystick is made through IDragHandler, IBeginDragHandler, IEndDragHandler.

The problem is that the events from Eventsystem are called before the Touch, so when i touch the screen Eventsystem will compute an empty space and then the touch will move the joystick to the touched position.

How can i force Eventsystem to execute BeginDrag after the joystick have being moved to its position?

I know that there's the ExecuteEvents.Execute(); but i can only make PointerUp and Down to work, drag dosen't.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by EDevJogos · Dec 25, 2017 at 08:15 PM

Found out a solution.

First i was trying to use ExecuteEvents.Execute() passing a new PointerEventData which dosen't work, you have to use the current PointerEventData from the EventSystem you can get it in most EventSystem interfaces like: IPointerClickHandler

 public void OnPointerClick(PointerEventData eventData)
 {
     if(JoystickController.CurrentPointer == null)
     {
         //Store the EventSystem PointerEventData for future use.
         JoystickController.CurrentPointer = eventData;
     }
 }

Than just store it somewhere, and at the Touch or Mouse click call, you have to set the pointerDrag object and call the ExecuteEvents with the event initializePotentialDrag, like:

 CurrentPointer.pointerDrag = joystick.gameObject;
 
 ExecuteEvents.Execute(joystick.gameObject, CurrentPointer, ExecuteEvents.initializePotentialDrag);

Note. You can't call ExecuteEvents from the same object that will recieve the Event, it won't work.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image cgascons · Jul 04, 2018 at 11:06 AM 0
Share

Hi, I've tried this solution and it doesn't really work for me. In my situation, I got a bunch of game objects implementing the drag interfaces inside a parent container which has a ScrollRect component.

When implementing your solution, and after adding a log in OnBeginDrag, OnDrag and OnEndDrag the only thing I get is one debug line per function called, i.e., it's only being called once, so I can actually see how the object moved in 1 frame.

Note: I had to make a call to initializePotentialDrag, OnBeginDrag and OnDrag (looping this one to test makes the object move) to be able to see some changes, calling only ExecuteEvents.initializePotentialDragdidn't to anything. Also, I'm actually able to call this from within the same gameobject and works. Finally, I'm enabling this script in runtime so when I'm calling it the button is already pressed in which case the OnBeginDrag is never called? Not really sure.

Any ideas of why this could be happening?

Thanks in advance!

avatar image Geaxle · Oct 03, 2018 at 03:51 PM 1
Share

If anyone else reads this thread, this worked very well for me.

For a bit more details:

The thing that seems to bug is only InitializePotentialDrag. So you only need to change this and not all the other drag method (they will work normaly once InitializePotentialDrag has been sent).

I didn't store the PointerEventData but sent it directly and then added this line: pointerData.pointerDrag = targetObject;

 void IInitializePotentialDragHandler.OnInitializePotentialDrag (PointerEventData eventData)
 {
     eventData.pointerDrag = $$anonymous$$yTarget.gameObject;
     ExecuteEvents.Execute<IInitializePotentialDragHandler> ($$anonymous$$yTarget.gameObject, eventData, ExecuteEvents.initializePotentialDrag);
 }
 
 void IBeginDragHandler.OnBeginDrag (PointerEventData eventData)
 {
     ExecuteEvents.Execute<IDragHandler> ($$anonymous$$yTarget.gameObject, eventData, ExecuteEvents.dragHandler);
 }

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

175 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Detecting onDrag over UI images 1 Answer

Drag and Swap two object using touch 0 Answers

Touch - drag different objects 1 Answer

Dragging Camera based on Touch 0 Answers

how create flipping book effect like apple ibook with touch ? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges