How to do it...

  1. Create a new Actor subclass in the editor, which we will name Barracks:
  1. Then, add the following implementation to the class:
UCLASS()class CHAPTER_04_API ABarracks : public AActor{    GENERATED_BODY()    public:     // Sets default values for this actor's properties    ABarracks();protected:    // Called when the game starts or when spawned    virtual void BeginPlay() override;public:     // Called every frame    virtual void Tick(float DeltaTime) override;    UPROPERTY()     UStaticMeshComponent* BuildingMesh;     UPROPERTY()     UParticleSystemComponent* SpawnPoint;          UPROPERTY()     UClass* UnitToSpawn;          UPROPERTY()     float SpawnInterval;          UFUNCTION() 

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.