Pointer Click fired outside of game object?

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:
```csharp
*public void OnTimelineBarClicked(BaseEventData data)

{
PointerEventData pointerData = data as PointerEventData;

        Vector2 localCursor;
        if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(pointerData.pointerPress.GetComponent<RectTransform>(), pointerData.position, null, out localCursor))
            return;

        if (IsDebug)
            Debug.Log("TimeLineclicked " + localCursor);

}[/I]*
```

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:

What am I not understanding ?

I have never used those (Event Triggers), but I’m aware of them. I wouldn’t have thought they’d fire outside the scope, either.
You could try this: Redirecting to latest version of com.unity.ugui
if that behaviour is not what you want. :slight_smile:

@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.

2 Likes

@fwalker

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

Nice posts :slight_smile:

eses,

I think you are on to something. It did not occur to me to check the pivot. I will investigate and report back :slight_smile: