Search Unity

EventSystem: how do you use IDropHandler.OnDrop with 3D objects?

Discussion in 'UGUI & TextMesh Pro' started by laurentlavigne, Apr 9, 2015.

  1. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,363
    I am dragging 3D objects by implenting I*DragHandler EventSystem in a Drag.cs script (OnBeginDrag,OnDrag, OnEndDrag). It works well and gets nicely occluded by UI buttons.
    Note that the 3D objects have colliders in them.

    I would like to implement drop.
    I attach a Drop script on the target and implementing IDropHandler.OnDrop(PointerEventDataeventData) in this script.
    When I Debug.Log(eventData) I get nothing when I drop the dragged object.

    I figure that maybe the object colliders are occluding the event system raycasting and prevent the raycast from reaching the dropped object so I implemented
    Code (CSharp):
    1. canvas = gameObject.AddComponent<CanvasGroup>();
    2. canvas.blocksRaycasts = false;
    inside OnBeginDrag of the dragged object but it's still not recognizing the OnDrop.

    What is the secret sauce?
     
  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
  3. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,363
    Read my post, I'm talking about drag and drop with 3D objects with colliders, not UI.
     
  4. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624
    Hi, add a physics ray caster to your camera
     
    CharlesYin likes this.
  5. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,363
    There is already a Physics Raycaster attached to my camera.
    All the 3D objects already respond to drag and clicks.
     
  6. holyjewsus

    holyjewsus

    Joined:
    Mar 7, 2011
    Posts:
    624
    ahh, i see, just disable the collider on the object that is being dragged, then re-enable it after drag ends.

    also just to clarify, you are implementing OnDrop to the target object, not the dragged object?
     
    Last edited: Apr 14, 2015
  7. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,363
    That's right, ondrop on the target, like with a UI.
    That's what I thought I need to disable colliders by hand. I logged a bug on that.
     
  8. CapnCromulent

    CapnCromulent

    Joined:
    Sep 7, 2010
    Posts:
    45
    @laurentlavigne, were you ever able to get this working with a 3d object?
     
  9. brainydexter

    brainydexter

    Joined:
    Apr 4, 2016
    Posts:
    21
  10. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,363
    It did work, just had to toggle off the object's collider.