How to do it...

  1. Create a new StaticMeshActor class called Tree using the editor.
  2. Insert the following code above the class declaration:
#pragma once#include "CoreMinimal.h"#include "Engine/StaticMeshActor.h"#include "Tree.generated.h"UENUM(BlueprintType)enum TreeType{    Tree_Poplar,    Tree_Spruce,    Tree_Eucalyptus,    Tree_Redwood};UCLASS()class CHAPTER_09_API ATree : public AStaticMeshActor{
  1. Add the following to the Tree class:
UCLASS()class CHAPTER_09_API ATree : public AStaticMeshActor{    GENERATED_BODY()    public:    // Sets default values for this actor's properties    ATree();    UPROPERTY(BlueprintReadWrite)    TEnumAsByte<TreeType> Type;};
  1. Add the following to the Tree constructor:
#include "Tree.h"#include "ConstructorHelpers.h"// Sets default values ...

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.