How to do it...

  1. Create a new GameModeBase subclass called ClickEventGameMode:
  1. From the ClickEventGameMode.h file, add the following functions and private members to the class:
#pragma once#include "CoreMinimal.h"#include "GameFramework/GameModeBase.h"#include "SlateBasics.h"#include "ClickEventGameMode.generated.h"UCLASS()class CHAPTER_14_API AClickEventGameMode : public AGameModeBase{    GENERATED_BODY()    private:    TSharedPtr<SVerticalBox> Widget;    TSharedPtr<STextBlock> ButtonLabel;public:    virtual void BeginPlay() override;    FReply ButtonClicked();};
  1. Within the .cpp file, add the implementation for BeginPlay:
void AClickEventGameMode::BeginPlay() ...

Get Unreal Engine 4.x Scripting with C++ Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.