Search Unity

Bug IDropHandler called only when dropping on items after dropped object in the hierarcy

Discussion in 'UGUI & TextMesh Pro' started by LDiCesare, Jul 27, 2022.

  1. LDiCesare

    LDiCesare

    Joined:
    Apr 20, 2018
    Posts:
    52
    I'm doing an inventory with a grid layout.
    Each item in the layout is an item slot.
    When I drag an item to somewhere below or to the right, OnDrop is correctly called on target slot.
    If I drag above, it is not called.
    upload_2022-7-27_11-50-37.png

    Each InventorySlot object is a GameObject with 2 UI image children (one for the item, one for the background).
    They are in a GridLayoutGroup in a scrollview.
    The InventorySlot has a script looking like this:
    public class InventorySlot : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler,
    IBeginDragHandler, IDragHandler, IEndDragHandler, IDropHandler

    I disabled the gridlayout, and whether OnDrop is called or not depends on whether the drop target is above or below the dragged object in the content. So it's not a question of geometry but the order of the transform children.

    Still, this is extremely puzzling.

    This is caused by the fact I move the image as I drag it, so it receives the OnDrag event instead of the intended target, but it does so ONLY if it is an elder child in its parent transform.

    The behavior should be consistent.
     
    Last edited: Jul 27, 2022