How to do it...

  1. Create a new StaticMeshActor class called Spotter. Remember to use the Show All Classes button to select StaticMeshActor as the parent class.
  2. Make sure that the following functions are defined and overridden in the class header:
#pragma once#include "CoreMinimal.h"#include "Engine/StaticMeshActor.h"#include "Spotter.generated.h"UCLASS()class CHAPTER_09_API ASpotter : public AStaticMeshActor{  GENERATED_BODY()  public:    // Sets default values for this actor's properties    ASpotter();    // Called every frame    virtual void Tick(float DeltaSeconds) override;    UFUNCTION(BlueprintImplementableEvent)    void OnPlayerSpotted(APawn* Player);};
  1. In the implementation file (Spotter.cpp), update the code to the following:
#include "Spotter.h" ...

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.