Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Hunted223 · Dec 30, 2017 at 12:46 AM · dragdrag-and-dropdraggingdraggable

OnBeginDrag, OnEndDrag not being called for unknown reasons

Hello there. So I'm fairly new to Unity, and have been following tutorials and the such. I'm now in the process of making my first game. Since I'm new, I've been adapting things from tutorials and example projects to build my game.

I've decided to reproduce a classic card game. For this card game, I'd like to drag cards, which would follow the mouse pointer around, until dropped in certain zones. I'd like to use the IDragHandler to make a script which I can attach to UI elements on a canvas to have their position adjusted to the position of the mouse when it is being dragged.

To do this, I need to detect when an object is dragged. Baby steps first, using the following code I should get a console log when I begin and stop dragging objects :

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.EventSystems;
 using UnityEngine.UI;
  
 [RequireComponent(typeof(Image))]
 public class Draggable : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
 {
  
  
     void Start()
     {
         Debug.Log("GameStart");
     }
  
     public void OnBeginDrag(PointerEventData eventData)
     {
         Debug.Log("OnBeginDrag");
     }
  
     public void OnDrag(PointerEventData eventData)
     {
      
     }
  
     public void OnEndDrag(PointerEventData eventData)
     {
         Debug.Log("OnEndDrag");
     }
 }

I attached this script to a UI image, parented to a panel, parented to a Canvas with an EventSystem in the scene. I also added a Canvas Group component to the image and have interactable and blocks raycasting enabled. The Camera also has a 2-d Physics Raycaster attached. (I'm sure some of this is unnecessary, but I tried them anyhow)

When I run the scene and attempt to drag and drop my image, I expect the console to have three logs - GameStart, OnBeginDrag and OnEndDrag. However, all I have is GameStart.

I've compared to the Unity Samples : UI store asset and I also checked out a tutorial video by quill18 creates at this youtube link. I should be getting console debug logs, but I'm not and am at a loss as to what to check for next.

Any help would be greatly appreciated.

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
0
Best Answer

Answer by Hunted223 · Dec 31, 2017 at 12:42 AM

Thanks to some knowledgeable friends in Twitch Chat, the answer was found and I figured I would share here.

It seems that some time between 2015 and now, an update was released that changed the default setting on UI images. "Raycast Target" on the "Image ( Script)" is now disabled by default and needs to be enabled for the DragHandlers to function properly.

Koodo's to kdo_92 and his twitch chat on Twitch.

Comment
Add comment · Show 3 · 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 KOORY · Apr 19, 2020 at 02:26 AM 0
Share

I still have the problem... :/ the project worked fine on Unity 5 but since i updated to 2019 i can't OnDrag my Joystick on any mobile.. only works in editor. Help?

avatar image Hunted223 · Apr 19, 2020 at 02:42 AM 0
Share

Perhaps you should start your own question? What you're asking isn't clear. There's no mention of a joystick anywhere in this question

avatar image KOORY Hunted223 · Apr 19, 2020 at 02:55 AM 0
Share

I tried but also got an error, I'll try again now/later

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

72 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

Related Questions

Possible to drag items across tabs onto the same frame? 1 Answer

Drag and Drop lagging behind mouse 0 Answers

How to transition a click-and-drag from a UI button to a GameObject 0 Answers

How to drag Unity Objects to other c# application 0 Answers

Drag and drop files from the assets folder to another folder not working 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