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. Dismiss Notice

Resolved IPointerEnterHandler on Sprite ignored when Collider2D present

Discussion in '2D' started by Ziplock9000, Jul 25, 2023.

  1. Ziplock9000

    Ziplock9000

    Joined:
    Jan 26, 2016
    Posts:
    360
    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
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    Have you tried using Layers? The GraphicRaycaster has a Blocking Layers mask property (see docs) but I've never used it.
     
  3. Ziplock9000

    Ziplock9000

    Joined:
    Jan 26, 2016
    Posts:
    360
    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."
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    But you haven't mentioned putting it on some other Layer and telling the Graphic Raycaster to ignore it.
     
    Ziplock9000 likes this.
  5. Ziplock9000

    Ziplock9000

    Joined:
    Jan 26, 2016
    Posts:
    360
    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.
     
    Kurt-Dekker likes this.
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    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. :) Glad you're casting safely. TIL...
     
  7. Ziplock9000

    Ziplock9000

    Joined:
    Jan 26, 2016
    Posts:
    360
    Actually it's the Physics 2D Raycaster that I changed to ignore that layer that worked, but I get your point
     
    Kurt-Dekker likes this.
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    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. :)
     
    Kurt-Dekker and Ziplock9000 like this.