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 /
  • Help Room /
avatar image
0
Question by aaronp261 · Oct 18, 2016 at 04:36 PM · c#eventsystemdraggingdrag and drop

Checking if over UI during onEndDrag - EventSystem.isPointerOverGameObject is not working as expected

I've built a basic drag and drop, from icons in the UI into the scene.

I'm currently having an issue with detecting if while onEndDrag the user is still over the UI as I want to block item creation.

I'm using the standard method to test if the user is still over the UI, but it is always returning true. I imagine this as the start of the drag and drop is from the UI. - Is there anyway to get around this? - Is this a potential bug?

  bool IsPointerOverGameObject(int fingerId)
 {
     EventSystem eventSystem = EventSystem.current;
             return (eventSystem.IsPointerOverGameObject(fingerId)
                 && eventSystem.currentSelectedGameObject != null);
 
 }

Above is my C# implementation to check if the pointer is over the UI. This is called in the onEndDrag function.

 public virtual void OnEndDrag(PointerEventData eventData)
 {
 ..
 
 if (!IsPointerOverGameObject(eventData.pointerId))
 
 ..
 }

Any help would be highly recommended.

Comment
Add comment · Show 4
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 aaronp261 · Nov 07, 2016 at 04:09 PM 0
Share

Anyone had any luck with checking if pointer is over UI within OnEndDrag?

avatar image hexagonius · Nov 07, 2016 at 05:31 PM 0
Share

Just to be sure. You are not moving the object you're dragging and you release the pointer outside the object?

avatar image aaronp261 hexagonius · Nov 07, 2016 at 05:39 PM 0
Share

Pretty sure, I will give it another test.
- Will make sure to disable as many canvas UI elements as I can as well.

On a side note: I do a number of other isPointerOverUI checks which all work as expected, notably this is the only one within an OnEndDrag handler.

avatar image aaronp261 hexagonius · Nov 07, 2016 at 05:46 PM 0
Share

So I've ran through my code and implementation, I've added this log line to display which game object it thinks the pointer is over.

Debug.Log("StandardDragDropCursor - OnEndDrag - OVER GA$$anonymous$$E OBJECT: " + EventSystem.current.currentSelectedGameObject.name);

Example output:

StandardDragDropCursor - OnEndDrag - OVER GA$$anonymous$$E OBJECT: Bedroom2_Icon UnityEngine.Debug:Log(Object) StandardDragDropCursor:OnEndDrag(PointerEventData) (at Assets/......../StandardDragDropCursor.cs:95) UnityEngine.EventSystems.EventSystem:Update()

This log will always output the name of the UI element I activate the Drag Handlers, regardless if I drag my pointer over another UI element or no UI element.

How strange, I'm 90% sure this is a bug. Or it is intended, if Unity has some sort of assumption that on drag brings the UI element with it?

  • I'm going to give this a go: Rather than use eventData from the handle, get the input position using mousePointer potentially.

1 Reply

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

Answer by aaronp261 · Mar 04, 2017 at 02:34 PM

So I've found a solution,

Implementing both IPointerExitHandler, IPointerEnterHandler and storing IsOverUI in a private bool so I can use this to check, it's not a perfect solution but the only usable one I've found.

If anyone has experienced this or solved with a more complete solution that would be great.

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

246 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

Related Questions

Drag and drop like clash of clans 0 Answers

Best Practices for touch event on GameObject C#,Best Practices for touch events C# 1 Answer

OnDrag is moving all colliders on Touch? (Not on Standalone) 0 Answers

UnityEngine.GameObject' does not contain a definition for `SetSelectedGameObject' 0 Answers

How to drag multiple object simultaneously??? 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