1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. We want to know how you learned Unity! Help us by taking this quick survey and have a chance at a $25 gift card
    Dismiss Notice
  5. Are you an artist or level designer going to Unite Europe? Join our roundtables there to discuss artist features.
    Dismiss Notice
  6. Unity 5.6 is now released.
    Dismiss Notice
  7. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice

Pointer Click fired outside of game object?

Discussion in 'Unity UI & TextMesh Pro' started by fwalker, Jun 14, 2017.

  1. fwalker

    fwalker

    Joined:
    Feb 5, 2013
    Posts:
    63
    I have a game object to which I have attached a Event Trigger script. What would cause the Pointer Click event to fire when clicking outside of the component/game object?

    This is what I am doing, in code, to get the location of the click. this is the method called from the Event Trigger on Pointer Click:

    Code (CSharp):
    1.  
    2.  
    3. public void OnTimelineBarClicked(BaseEventData data)
    4.  
    5. {
    6.             PointerEventData pointerData = data as PointerEventData;
    7.  
    8.             Vector2 localCursor;
    9.             if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(pointerData.pointerPress.GetComponent<RectTransform>(), pointerData.position, null, out localCursor))
    10.                 return;
    11.  
    12.             if (IsDebug)
    13.                 Debug.Log("TimeLineclicked " + localCursor);
    14. }[/I]
    15.  
    This code returns negative numbers. Which I would not expect. It also returns numbers that are larger than the actual size (width) of the component. I am only focusing on the x component.

    The component inspector looks like this:

    [​IMG]

    What am I not understanding ?
     

    Attached Files:

  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    2,433
  3. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    647
    @fwalker

    hi,

    I don't think you should get that. You actually have a UI GameObject with RectTransform... so it should get the clicks only when you hit it's rect.

    One case that comes to my mind:
    Your UI RectTransform could have a child. Those too will get the clicks.

    But it is hard to say what is going on based on your explanation, I don't see your hierarchy etc.

    Also, remember that there is nothing wrong getting negative coordinates for clicks, clicks in RectTransform are in RectTransform coordinates, which are relative to pivot of RectTransform... so if you have a center pivot, any clicks below pivot and to left of it will be negative values.
     
    Last edited: Jun 19, 2017 at 9:43 PM
  4. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    647
    @fwalker

    I just did a quick test in clean scene, it worked just fine with the RectTransform values you used, and using your code.
     
  5. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    2,433