IPointerEnterHandler on Sprite ignored when Collider2D present

I have a 2D Unity project, where I can highlight sprites by moving the mouse over them and responding to the OnPointerEnter via IPointerEnterHandler and dimming the sprite.

I also have empty GO’s with Collider 2D’s set to trigger that respond to the player walking into them and offering a quest for example.

However when they overlap, the former (sprite highlight) never happens and I don’t see a way to change layer orders or something.

I’ve tried putting the trigger collider 2d on the ‘Ignore Raycast’ layer, which in theory should work, but it doesn’t.

How do I fix this? BTW I wont use a solution that polls in Update or the like

Have you tried using Layers? The GraphicRaycaster has a Blocking Layers mask property (see docs) but I’ve never used it.

I mention this:
“I’ve tried putting the trigger collider 2d on the ‘Ignore Raycast’ layer, which in theory should work, but it doesn’t.”

But you haven’t mentioned putting it on some other Layer and telling the Graphic Raycaster to ignore it.

1 Like

Ah I see what you mean. I only did half the job. I was assuming that the ‘Ignore Raycast’ layer was already set up to be ignored when it wasn’t.
So yes, I changed the raycast to ignore that layer and it now works.
Thanks
I feel silly for not testing that earlier.

1 Like

I think in terms of lineage, “ignore raycast” dates back to the earliest days of Physics.Raycast.

For whatever reason, the much-more-modern GraphicRaycaster simply doesn’t involve itself in such a specific layer like that.

At least that’s my theory. :slight_smile: Glad you’re casting safely. TIL…

Actually it’s the Physics 2D Raycaster that I changed to ignore that layer that worked, but I get your point

1 Like

So you know though, none of this is 2D. Neither the physics team nor the 2D team created it, use it or maintain it. It’s all UI stuff. This is also true for the Physic2DRaycaster. :slight_smile:

2 Likes