Send additional parameters to callback

Is there some way to send an additional parameter to a callback, or at least, get the name of the button or element that originated the event?

Try the following:

static void OnMouseUp(MouseUpEvent evt, Whatever we)
{
    // Do stuff.
}

void RegisterToElement(VisualElement ve, Whatever we)
{
    ve.RegisterCallback<MouseUpEvent, Whatever>(OnMouseUp, we);
}
1 Like

All events have a target parameter that contains the element where the event originated from:

void OnMouseUp(MouseUpEvent evt) {
    var button = evt.target as Button;
    ...
}

and Button specifically has an overload for its callback that takes an event as an argument:

var button = new Button();
button.clickable.clickedWithEventInfo += (evt) => Debug.Log((evt.target as Button).name);
1 Like