Hi.
I have a custom widget that inherits from UserWidget. And now Im trying to create custom buttons to be able to override the “OnClicked” functionality.
I’ve realized there is a simple way to add Buttons to the widget:
TSharedPtr<SHorizontalBox> Container = SNew(SHorizontalBox);
Container->AddSlot()
[
SNew(SButton)
];
GEngine->GameViewport->AddViewportWidgetContent(Container);
But I haven’t found a way from the unreal editor to create a class that inherits from SButton . I did found a way to create a Button class that inherits from UButton. and I have overrided the OnClicked method, so everything should be ready, I would just need to add my “XButton” to my widget. But no idea how to! since is not an SButton.
Another possible solution I’ve think of is create my own Clicked method inside my custom widget and then Bind that method to the SButton before sending it to the container. But I haven’t got any luck either. The way I’m doing it is:
CustomWidget.h
public:
FOnClicked TryClickedMethod;
FReply ClickedMethod(float x);
float t;
CustomWidget.cpp
void CustomWidget::Initialize()
{
TryClickedMethod.BindUFunction(this, "ClickedMethod",t);
TSharedPtr<SHorizontalBox> Container = SNew(SHorizontalBox);
Container->AddSlot()
[
SNew(SButton).OnClicked(TryClickedMethod)
];
}
FReply CustomWidget::ClickedMethod(float x)
{
x += 1;
return FReply::Handled();
}
I get this error.
"FReply::FReply : No appropiate
default constructor available
How could I add my custom Button to the widget? and in case I can’t because I need an SButton, how could I create one? or how can I assign the function so when this button is been clicked my function will be called with the float parameter?
Thanks!
Update1: if I make FReply ClickedMethod an UFunction:
UFUNCTION(BlueprintCallable, Category = "ClickedTry")
FReply ClickedMethod(float x);
I get
Unrecognized type ‘FReply’
But I have #include "Reply.h"