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

ExecuteDefaultActionAtTarget not getting MouseDown/Up events, but RegisterCallback<> works?

Discussion in 'UI Toolkit' started by dyamanoha_, Jun 17, 2022.

  1. dyamanoha_

    dyamanoha_

    Joined:
    Mar 17, 2013
    Posts:
    78
    I've overriden ExecuteDefaultActionAtTarget on a custom control. Instances of the VisualElement receive MouseEnter/Leave events but not MouseDown/Up events. Registering for the callbacks directly works just fine. Why aren't they passed to ExecuteDefaultActionAtTarget?

    Code (CSharp):
    1. protected override void ExecuteDefaultActionAtTarget(EventBase evt)
    2. {
    3.    base.ExecuteDefaultActionAtTarget(evt);
    4.  
    5.    // This works
    6.    if (evt.eventTypeId == AttachToPanelEvent.TypeId())
    7.    {
    8.        RegisterCallback<MouseDownEvent>(OnMouseDown);
    9.    }
    10.  
    11.    // This doesn't
    12.    if (evt.eventTypeId == MouseDownEvent.TypeId())
    13.    {
    14.        OnMouseDown((MouseDownEvent)evt);
    15.    }
     
    479813005 likes this.
  2. dyamanoha_

    dyamanoha_

    Joined:
    Mar 17, 2013
    Posts:
    78
    Note I just starting browsing UITookit source and noticed they recently added the `EventInterest` attribute, so I upgraded and annotated the method with `[EventInterest(typeof(AttachToPanelEvent), typeof(MouseDownEvent))]`, but that didn't get the MouseDownEvents to show up.
     
  3. dyamanoha_

    dyamanoha_

    Joined:
    Mar 17, 2013
    Posts:
    78
    Never mind, I think I figured it out. The custom control I created has two child elements that fill it's entire space. I guess I need to register for events so I can handle them during the trickle down phase. At the moment I do get MouseDown events but only on the border of the container VisualElement.
     
  4. IAMSUPERMAN

    IAMSUPERMAN

    Joined:
    Sep 9, 2022
    Posts:
    1
    You can specify picking mode for your children.
    Code (CSharp):
    1. circle = new VisualElement();
    2. circle.pickingMode = PickingMode.Ignore;
     
  5. 479813005

    479813005

    Joined:
    Mar 18, 2015
    Posts:
    58
    I have the same problem, is there any progress on this issue