Send bool from widget to character

Widgets are not UObjects so you can’t use the UPROPERTY or UFUNCTION macros here.

You should take a look at SCheckBox (Slate) and UCheckBox (UObject)

First you Declare the delegate which you have done although you don’t have to name the bool parameter.

Then you declare the Delegate but without the UPROPERTY macro.

Then you pass the delegate as an argument to the slate constructor using the initializer list.

SLATE_BEGIN_ARGS(SConstructionWidget) : _OnBuildingClicked() {}

In the Construct implementation you assign the slate argument to your delegate member variable.

OnBuildingClicked = InArgs._OnBuildingClicked;

You then need to execute the delegate whenever you like with the appropriate value.

OnBuildingClicked.ExecuteIfBound(true);

The final task is to bind a UObject callback function to this delegate possibly in your Character class.

First you create the callback function that takes a bool as a parameter.

void SlateOnBuildingClickedCallback(bool EnteredConstructionMode);

Then when you create an instance of your widget you bind your callback functions to the widget delegate using the macro BIND_UOBJECT_DELEGATE

MyConstructionWidget = SNew(SConstructionWidget)
		.OnBuildingClicked( BIND_UOBJECT_DELEGATE(FBuildingClickedSignature, SlateOnBuildingClickedCallback) )

Again I recommend you look at SCheckBox (Slate) and the UCheckBox (UObject) code if you get lost.

I hope this helps.

1 Like