I’m trying to make this system of buttons, in which i want each button hover event to call the exact same function, but with a different parameter. This is what the code looks like:
switch (i)
{
case 0:
Cast<UButton>(Buttons[i])->OnHovered.AddDynamic(this, &UBaseUIWidget::ButtonBind1);
break;
case 1:
Cast<UButton>(Buttons[i])->OnHovered.AddDynamic(this, &UBaseUIWidget::ButtonBind2);
break;
case 2:
Cast<UButton>(Buttons[i])->OnHovered.AddDynamic(this, &UBaseUIWidget::ButtonBind3);
break;
}
void UBaseUIWidget::ButtonBind1()
{
UpdateSelectorLocation2(0);
}
void UBaseUIWidget::ButtonBind2()
{
UpdateSelectorLocation2(1);
}
void UBaseUIWidget::ButtonBind3()
{
UpdateSelectorLocation2(2);
}
I’m 99% sure there’s a better way to do this. I already checked the delegates wiki and the function pointers wiki, but i get the impression i have to define every single one of these functions (also i only included 3 binds here, but i have over 10 of them)…
Any help would be appreciated, thanks