Get sender when Widget OnPressed is called

I now have 8 buttons. Do I need to write code like

	UButton* Button01 = Cast<UButton>(GetWidgetFromName("Button_PickCharacter1"));
	FScriptDelegate Del01;
	Del01.BindUFunction(this, "OnCharacterSelected01");
	Button01 ->OnPressed.Add(Del01);
UButton* Button02 = Cast<UButton>(GetWidgetFromName("Button_PickCharacter2"));
	FScriptDelegate Del02;
	Del02.BindUFunction(this, "OnCharacterSelected02");
	Button02 ->OnPressed.Add(Del02);
       .
       .

The code above is so dump and redundant.
Can we just use bind function ,then tell which button trigger the event in this callback function ?

Thanks

Unfortunately as far as I know this is not supported with this type of delegate (TScriptDelegate / TMulticastScriptDelegate), because they only support UFUNCTION’s and do not offer any virtuals to override.

I have been there though and my general go-to solution is to subclass the Button class, bind the OnPressed event internally and broadcast my own custom event dispatcher which includes self as parameter.

1 Like

Thanks
I let each button widget call itself, then broadcast / send to its parent widget.
:slight_smile: