Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity UI [Solved] Need interactable element that does NOT block raycasts or use events

Discussion in 'UGUI & TextMesh Pro' started by Sun-Dog, Mar 16, 2018.

  1. Sun-Dog

    Sun-Dog

    Joined:
    Mar 23, 2009
    Posts:
    144
    I'm trying to solve this problem:
    https://forum.unity.com/threads/trying-to-detect-a-drop-directly-on-the-canvas.522017/

    What I'm trying to do is this:
    DropOnNothing.png

    *BG Graphic shamelessly taken from https://cheatcc.com/pc/rev/diablo3reaperofsoulsreview.html for illustration purposes only!

    My current thought is to stretch a transparent element under the entire UI... however...

    This element needs to be INTERACTABLE but NOT BLOCK RAYCASTS into the scene.

    I've tried using Canvas groups, but this seemed to be all or nothing and does either one (Interactable) or the other (Not block raycasts). I can't figure out how to do both on the same element.

    I'm toying with the idea that I have some sort of script that takes the used event and un-uses it, but this seems nutty.

    Can anyone else either think of a way to get an interactable element that does not block raycasts or use events, or a new thought about how to achieve the overall goal of dropping on the scene and get a UI Event?
     
  2. Sun-Dog

    Sun-Dog

    Joined:
    Mar 23, 2009
    Posts:
    144
    I was hoping that the canvas group would work out of the box with these settings:

    4a5ad68aa4da995376fca02ca8e19457.png

    But sadly, no.

    If "Blocks Raycasts" is false, then there is no detected interaction.
     
  3. Sun-Dog

    Sun-Dog

    Joined:
    Mar 23, 2009
    Posts:
    144
    SOLUTION:

    It's a bit hacky but:

    I've stretched a full screen fully transparent image panel across the screen under the UI. Let's call this a "drop catcher".

    I take a reference to the drop catcher GameObject (but I could just as easily grab the Image or the RaycastTarget or a number of other properties) and I SetActive(false); when the game starts. Then when I grab the Icon I'm dragging in the UI (as the player won't be interacting with the scene while dragging an icon) I set the drop catcher as active just in case the icon gets dropped on the scene. Lastly, I have to - in every possible instance of OnDrop in the UI and in the code on the drop catcher itself - make sure that the drop catcher layer is set to be inactive when the drag is done and the item is dropped.

    Phew.

    A bit hacky, I feel, but it works. The layer is active when dragging and not when the drag ends and the icon is dropped. I will detect the drop on the scene if it happens.

    If anyone can think of a better way to do this, please let me know, and if you're running up against the same issue, I hope this helps.
     
    IgorAherne likes this.
  4. IgorAherne

    IgorAherne

    Joined:
    May 15, 2013
    Posts:
    393
    Colin_MacLeod likes this.