Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

OnPointerExit repeatedly calls during drag operation.

Discussion in 'Scripting' started by SoCentral2, Nov 20, 2015.

  1. SoCentral2

    SoCentral2

    Joined:
    Oct 6, 2015
    Posts:
    10
    I have 2 image objects in my project and I want to drag one over the other. When I drag object 1 over object 2 I use OnPointerEnter to increase the alpha of object 2 and OnPointerExit to decrease it again.

    Testing shows that OnPointerExit keeps firing despite the mouse not exiting the bounds of the target object. I'm getting one OnPointerExit for between every two and five 'OnDrag's.

    Before I spend ages stripping out all the extra code on an extensive bug hunting mission, I'm wondering if there's something well-known or obvious I'm missing.
     
  2. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    maybe the ray of the PointerExit gets interrupted while Dragging, how are you dragging the objects?
     
    SoCentral2 likes this.
  3. SoCentral2

    SoCentral2

    Joined:
    Oct 6, 2015
    Posts:
    10
    Doh! Thank you for that, it was one of the first things I looked at, 6 hours ago (I remembered watching
    21m30 recently) - but then I got sidetracked and completely forgot about it :-(

    Code (CSharp):
    1. GetComponent<CanvasGroup>().blocksRaycasts = false;
    in BeginDrag and

    Code (CSharp):
    1. GetComponent<CanvasGroup>().blocksRaycasts = true;
    in EndDrag solved it.

    Double Doh!