Button OnPressed delegate triggered twice when dynamically constructed

So I have a UUserWidget derived class in c++ that contains a UButton derived class. Within this UButton derived class, I also replaced RebuildWidget with the construction and assignment of my own SButton subclass, which I assign to MyButton.

Inside this UserWidget, I create the UButton in RebuildWidget, with a if(!MyButton) guard around it. I then bind to its OnPressed delegate in NativeConstruct().

For some reason, this triggers OnPressed twice. OnClicked still only triggers once, but OnPressed triggers twice.

Any help appreciated.

everything you’ve described here doesn’t really point to why this gets triggered twice. i’m not sure if you’ve also called the parent’s construction functions which also bind the delegate so if you find bound the delegate twice then when it receives the on pressed input hooks it may be firing both delegates going to one pressed?

As a workaround, you can put in a do-once node or a anti-double-press spam prevention. So it’s a sort of very short timer ball loop function. So even if you get the double-click for on-pressed.

on click is down and up so even if the on pressed input down receives two inputs you need a down and an up input for the clicked to register.

Well I specifically need pressed and released to trigger separate logic, for things like held buttons and such.

Again, the very odd thing is that I bind on native construct, and my breakpoint on CustomButton->OnPressed.AddUniqueDynamic(this, &UMyWidgetClass::OnPressed_Forward); it gets tripped once when starting PIE.

However the bound function gets triggered twice somehow. My slate button Pressed is only triggered once when I press it as well. I mean I have to wonder if its related to how slate handles inheritance. I overrode RebuildWidget without calling the parents function, however I wonder if the parents implementation is somehow still being executed here and creating a normal SButton that’s getting bound?

okay so more specifically, when pressing the button it seems to immediately press and release, then press again

I wonder if it has something to do with this bit of UButton:

FReply UButton::SlateHandleClicked()
{
    OnClicked.Broadcast();

    return FReply::Handled();
}

void UButton::SlateHandlePressed()
{
    OnPressed.Broadcast();
    BroadcastBinaryPostStateChange(UWidgetPressedStateRegistration::Bit, true);

}

void UButton::SlateHandleReleased()
{
    OnReleased.Broadcast();
    BroadcastBinaryPostStateChange(UWidgetPressedStateRegistration::Bit, false);
}

void UButton::SlateHandleHovered()
{
    OnHovered.Broadcast();
    BroadcastBinaryPostStateChange(UWidgetHoveredStateRegistration::Bit, true);
}

void UButton::SlateHandleUnhovered()
{
    OnUnhovered.Broadcast();
    BroadcastBinaryPostStateChange(UWidgetHoveredStateRegistration::Bit, false);
}


I mean OnClicked is the only one that doesn’t have BroadcastBinaryPostStateChange, so maybe with how unreal handles managing the pressed state doesn’t play nice with subclassing

okay disregard all of this. It was actually a mishandled switch statement I used to call the parent press implementation in SButton. I just swapped it out with if/else ifs to avoid any potential issues with it, and the issue went away