Slate Button OnClicked_Lambda

I’m trying to bind a lamda to the OnClicked event of the SButton like so:

SNew(SButton).OnClicked_Lambda([](){ GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Button Clicked!")); })

On compiling, I have the following error:

c:\program files\epic games\4.7\engine\source\runtime\core\public\delegates\Tuple.h(113): error C2664: 'FReply::FReply(const FReply &)' : cannot convert argument 1 from 'void' to 'bool'
          Expressions of type void cannot be converted to other types

I thought that maybe it’s waiting for the lamda to return a bool and made it to return one:

SNew(SButton).OnClicked_Lambda([]()->bool{ GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Button Clicked!")); return true; })

However, the error just changed to the:

c:\program files\epic games\4.7\engine\source\runtime\core\public\delegates\Tuple.h(113): error C2248: 'FReply::FReply' : cannot access private member declared in class 'FReply'

Now I just don’t have any ideas at all, maybe it’s some bug?

Would very appreciate any hints, thank you!

You need to return the type FReply, eg FReply::Handled();

SNew(SButton).OnClicked_Lambda([]()->FReply{ GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Button Clicked!")); return FReply::Handled(); })
1 Like

Working like a charm, thank you!