How to do it...

  1. Create a new C++ class derived from the StaticMeshActor class using the editor wizard; call it SlidingDoor.
  2. Add the following text that's in bold to the new class:
class CHAPTER_09_API ASlidingDoor : public AStaticMeshActor{    GENERATED_BODY()    public:     // Sets default values for this actor's properties    ASlidingDoor();protected:    // Called when the game starts or when spawned    virtual void BeginPlay() override;public:     // Called every frame    virtual void Tick(float DeltaTime) override;    UFUNCTION(BlueprintCallable, Category = Door)    void Open();    UPROPERTY()    bool IsOpen;    UPROPERTY()    FVector TargetLocation;};
  1. Create the class implementation by adding the following text in bold to the .cpp file:
#include "SlidingDoor.h"#include "ConstructorHelpers.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.