SButton OnClicked() Problems

Hey! I’ve found plenty of examples online and in the editor source code. I’ve tried them, but none worked…

Any help would be very much appreciated :slight_smile:

Errors:

  • ‘AsShared’: is not a member of ‘FVFEditorModule’ - C:\Program Files\Epic Games\UE_4.16\Engine\Source\Runtime\Core\Public\Delegates\DelegateSignatureImpl.inl - Line:197
  • ‘StaticCastSharedRef’: no matching overloaded function found - C:\Program Files\Epic Games\UE_4.16\Engine\Source\Runtime\Core\Public\Delegates\DelegateSignatureImpl.inl - Line: 197
  • ‘TBaseDelegate::CreateSP’: no matching overloaded function found - C:\Program Files\Epic Games\UE_4.16\Engine\Source\Runtime\Core\Public\Delegates\DelegateSignatureImpl.inl - Line: 197

VFEditor.h:

class FVFEditorModule : public IModuleInterface
{
public:
    // Plugin/Module functions
private:
    FReply OnNewButtonClicked();
    FReply OnOpenButtonClicked();
    FReply OnSaveButtonClicked();
};

VFEditor.cpp:

TSharedRef<SDockTab> FVFEditorModule::OnSpawnPluginTab(const FSpawnTabArgs& SpawnTabArgs)
{
    FText NewButton = FText::FromString("New File");
    FText NewToolTip = FText::FromString("Make a new .fga file!");

    return SNew(SDockTab)
        .TabRole(ETabRole::NomadTab)
        [
            // New file button
            SNew(SButton)
            .VAlign(VAlign_Center)
            .HAlign(HAlign_Center)
            .Text(NewButton)
            .ToolTipText(NewToolTip)
            .DesiredSizeScale(FVector2D(100.0f, 60.0f))
            .OnClicked(this, &FVFEditorModule::OnNewButtonClicked)
	];
}

FReply FVFEditorModule::OnNewButtonClicked()
{
    return FReply::Handled();
}

You are looking for OnClick_Raw.

.OnClicked_Raw(this, &FYourPluginNameModule::TestButtonFunction)

You can also use OnClick_Static for static function or OnClick_Lambda for lambdas

.OnClicked_Static(&FTutorialPluginEditorModule::TestButtonFunction)

.OnClicked_Lambda([]()
	{
		UE_LOG(LogTemp, Error, TEXT("BUTTON LAMBDA!!!!!")); 
		return FReply::Handled();
	})

You can also create custom widget (derived from SCompoundWidget) and build the widget in void Construct(const FArguments& InArgs);. The OnClick will work there. But for one button it is a bit of an overkill.

1 Like

Thank you very much :slight_smile:

Great answer! I wonder if you could provide a little example about how to create custom widget with some buttons and input areas? It will be really helpful!