Hi, thank you so much. I have tried for the past 4 hours now, but I can’t solve it. I’m looking at different tutorials on docs.unrealengine, benui, forums.unrealengine, chatGPT and old forum posts. All have hints, all seemingly doing it different. I just can’t combine the hints to any logic.
This is what I managed to conjure, doesn’t work.
#pragma once
#include "CoreMinimal.h"
#include "Widgets/SCompoundWidget.h"
#include "SlateBasics.h"
#include "SlateExtras.h"
DECLARE_DELEGATE_OneParam(FOnBuildingClickedDelegate, bool);
class MYGAME_API SConstructionWidget : public SCompoundWidget
{
public:
SLATE_BEGIN_ARGS(SConstructionWidget)
: _OnBuildingClickedDelegate()
{}
SLATE_ARGUMENT(TWeakObjectPtr<class AMenuHUD>, OwningHUD)
SLATE_EVENT(FOnBuildingClickedDelegate, OnBuildingClickedDelegate)
SLATE_END_ARGS()
void Construct(const FArguments& InArgs);
void HandlecanConstruct(bool EnteredConstructionMode) const;
FReply OnBuildingClicked() const;
FOnBuildingClickedDelegate OnBuildingClickedDelegate;
TWeakObjectPtr<class AMenuHUD> OwningHUD;
virtual bool SupportsKeyboardFocus() const override { return true; };};
And then the cpp file (the important parts):
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
void SConstructionWidget::Construct(const FArguments& InArgs)
{
bCanSupportFocus = true;
OwningHUD = InArgs._OwningHUD;
OnBuildingClickedDelegate = InArgs._OnBuildingClickedDelegate;
OnBuildingClickedDelegate.BindSP(this, &SConstructionWidget::HandlecanConstruct);
//...
//Building Button
+ SVerticalBox::Slot()
.Padding(ButtonPadding)
[
SNew(SButton)
.OnClicked(this, &SConstructionWidget::OnBuildingClicked)
//...
}
FReply SConstructionWidget::OnBuildingClicked() const
{
if (OwningHUD.IsValid()) {
HandlecanConstruct(true);
}
return FReply::Handled();
}
void SConstructionWidget::HandlecanConstruct(bool EnteredConstructionMode) const
{
OnBuildingClickedDelegate.ExecuteIfBound(true);
}
For my character whom is trying to receive the bool I have a function:
void canConstruct(bool EnteredConstructionMode);
And then in my character cpp I have:
void AMyCharacter::canConstruct(bool EnteredConstructionMode){
SConstructionWidget* ConstructionWidget = GetOwner<SConstructionWidget>();
ConstructionWidget->OnBuildingClickedDelegate.Add(this,
&AMyCharacter::FindConstructionSite);
}