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
0
Question by Siegewolf · Feb 13, 2019 at 12:56 AM · androiduicontrollereventsystemtouch controls

OnDrag methods not being called on Android in Unity 2018.3.5f1

I had the following kind of UI based player's controller code for an Android phone, and in Unity 2017.4.18f1 it worked as expected. In Unity 2018.3.5f1, none of the OnDrag methods get called, while OnPointer* methods do get called. Inside the editor in Windows using a mouse pointer to simulate touch controls, all of them still get called. Is this a bug in Unity 2018? Need help...

 public class VrJoypedAxis : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerUpHandler, IPointerDownHandler
 {
     ...
 
     void Start()
     {
         ...
     }
 
     public void OnBeginDrag(PointerEventData ped)
     {
         ...
     }
     
     public void OnDrag(PointerEventData ped)
     {
         ...
     }
 
     public void OnEndDrag(PointerEventData ped)
     {
         ...
     }
     
     public void OnPointerDown(PointerEventData ped)
     {
     }
 
     public void OnPointerUp(PointerEventData ped)
     {
         ...
     }
 }



UPDATE:
I tried alternative way, so this time I used "Event Trigger" component on an UI image object, with three events, pointer up, pointer down and drag. Alternative script looks like this::

 public class VrJoypedAxis : MonoBehaviour
 {
     public void Dragging() //Attached to Event Trigger component -> Drag
     {
         ...
     }
 
     public void ClickDown() //Attached to Event Trigger component -> Pointer Down
     {
         ...
     }
 
     public void ClickUp() //Attached to Event Trigger component -> Pointer Up
     {
         ...
     }
 }

And it doesn't work in exactly the same way as code above. With mouse cursor in Unity editor, all events work in both Unity 2017 and Unity 2018. On android device using touch input, in Unity 2017 all events also work but in Unity 2018, only pointer up and pointer down events work, while drag is dead.

As it looks to me, drag events are completely busted for touch input in Unity 2018.3.5f1.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
8
Best Answer

Answer by Siegewolf · May 04, 2019 at 09:54 PM

Finally found the problem.

 Cursor.lockState = CursorLockMode.Locked;


As of Unity 2018/2019, this command is disabling OnDrag events for touchscreen input when using Unity UI system. It might be doing the same not just in case of UI.

Don't know if it is a bug or intentional fix in Unity 2018/2019 (make somewhat sense that it is intentional), but once I remove this command, drag is working fine once again.

Comment
Add comment · Show 7 · 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 draky · Jul 08, 2019 at 03:11 AM 0
Share

Thank you for this. Don't know how much time you just saved me lol

avatar image adrianurma · Feb 08, 2020 at 02:13 PM 0
Share

Saved me man.. I have been struggling for days and now i find out that a line from an unrelated script a made same time ago used this lockstate.. Thank you sir

avatar image KOORY · Apr 19, 2020 at 01:19 AM 0
Share

@Siegewolf $$anonymous$$y project was working fine on Unity 5, now on 2019 got this problem.. I saw your reply but i just don't understand where to find this code to change? " Cursor.lockState = CursorLock$$anonymous$$ode.Locked;"

avatar image Siegewolf KOORY · Apr 19, 2020 at 08:33 AM 0
Share

That line of code was in one of my scripts. It may be in one of yours too, if it is the same problem.

avatar image KOORY Siegewolf · Apr 19, 2020 at 12:09 PM 0
Share

Unfortunately no, i looked through the whole thing did not find any. I genuinely started to lose hope solving this, as i literally read every single post about this problem and i still have it. I even posted question on Reddit and Stackoverflow got 0 solutions.

Show more comments
avatar image linojon · May 18, 2020 at 11:23 PM 1
Share

If using the legacy FPSController from Standard Assets, you can disable it in the Inspector, First Person Controller > $$anonymous$$ouse Look > Lock Cursor

avatar image
0

Answer by dma8 · Feb 16, 2019 at 01:09 AM

I was struggling with the same problem on iOS. Try setting the Max Ray Intersections to zero on your Physics Raycaster. I can't test on Android but hopefully this will work for you also. Apparently there is bug with the Physics Raycaster. See the post below.

Unity Event Trigger iOS

Comment
Add comment · Show 1 · 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 Siegewolf · Feb 16, 2019 at 02:02 AM 0
Share

The thing is, my virtual controller is based on Unity's UI system. This system is using Graphics Raycaster, not Physics or Physics2D Raycaster component. Graphics Raycaster is assigned as component to UI canvas by default when canvas is created. And according to Unity manual, Graphics Raycaster is the one that needs to be used with Unity's UI system and this one doesn't have $$anonymous$$ax Ray Intersections variable.

Regardless of this, I tried now to swap Graphics Raycaster with Physics one in UI canvas, but as expected, now whole UI is non-intractable even in Unity editor.

avatar image
0

Answer by alihaghshenas821 · Mar 16, 2021 at 11:38 PM

Cursor.lockState = CursorLockMode.Locked;

this didnt solve my problem and i couldnt find anything that show me a way to use IDragHandler in android i couldnt use EventTrigger cus i needed the dragging distance

actually i realized that i dont need dragging for what i need in my game but this might solve your problem if you are struggling with this issue like me

 public class AttackButtonCameraMove : EventTrigger
 {
     [SerializeField] private FixedTouchField _touchField;
 
     private void Awake()
     {
         _touchField = FindObjectOfType<FixedTouchField>();
     }

 
     public override void OnPointerDown(PointerEventData data) {
         _touchField.attackPuttonPressed = true;
         _touchField.PointerOld = data.pressPosition;
         _touchField.Pressed = true;
     }
 
     public override void OnPointerUp(PointerEventData data)
     {
         _touchField.Pressed = false;
         _touchField.attackPuttonPressed = false;
     }
 }

you can simply override OnDrag as well and it will work on android

Comment
Add comment · 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

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

280 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 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

Move object with touch 3D with script 0 Answers

Event System Not Working In UWP Build 2 Answers

uUI - OnSelect: From Mouse/Pointer or Keyboard/Controller? 0 Answers

Is there a way to fire the inspector events from code? 0 Answers

OnDrag OnPointerDown OnPointerUp does not work 1 Answer


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