Unity UI - Fallthrough detection? (Drag to pan camera if your input was not processed by the UI etc)

Hey ya’ll!

So, say I am working on a mobile game with similar controls to Boom Beach. I have a bunch of UI elements that the user can interact with, and the user can also pan around/pinch and zoom on the map.

Basically, I need my script to capture user touch inputs that have not been processed by the UI. I’d love to receive events like OnClick, OnDrag, etc, just like the UI.

NGUI let me do this by registering an object as the ‘fallthrough’ object - this object would receive all UI events that were not handled by UI elements.

Does UGUI have something similar?

I’m looking for the exact same thing, have you found a solution yet?

EventSystem doesn’t work the way NGUI does.

I had a system like yours for controlling the movement of my map. If the touch/drag/etc fell through it would send the messages to the script that handled Dragging the map.

Now, I have a script on the ground gameobject (with box collider) that does the following.

using UnityEngine;
using UnityEngine.EventSystems;

public class DragCamera : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
{
    private bool WorldDragging = false;
    private Vector3 DragStartPosition = new Vector3();

    public void OnBeginDrag(PointerEventData eventData)
    {
      
        DragStartPosition = eventData.pointerCurrentRaycast.worldPosition;
        WorldDragging = true;
                   
            
    }
    public void OnDrag(PointerEventData eventData)
    {
        if (WorldDragging)      
             Camera.main.transform.position += DragStartPosition - eventData.pointerCurrentRaycast.worldPosition;
       
    }
    public void OnEndDrag(PointerEventData eventData)
    {
        if (WorldDragging)
            WorldDragging = false;
    }
}

Actually, I didn’t like this solution ether.

Take a look at THIS thread to see a better solution that replicates the fallthrough functionality.

1 Like

Alright thank you very much, everything I found seemed either very clumpy or hacky. So for future reference ( and as told in the thread link ):

  • Create a 2D collider as a child of the camera (covering the view).

  • Attach a 2D Raycaster to your camera

  • Make sure the 2DRaycaster component is loaded after the 3D raycaster so 3D objects get hit first.

  • Attacht default/fallthrough functionality to 2D collider GameObject

Haven’t had time for testing much, but it seems like it will solve my headache. Thanks again Mycroft!