Enums are commonly used in C++ as flags or inputs to switch statements. However, what if you want to pass an enum
value to or from C++ from a Blueprint? Alternatively, if you want to use a switch
statement in Blueprint that uses an enum
from C++, how do you let the Blueprint editor know that your enum
should be accessible within the editor? This recipe shows you how to make enums visible in Blueprint.
Create a new
StaticMeshActor
class calledTree
using the editor.Insert the following code above the class declaration:
UENUM(BlueprintType) enum TreeType { Tree_Poplar, Tree_Spruce, Tree_Eucalyptus, Tree_Redwood };
Add the following
UPROPERTY
in theTree
class:UPROPERTY(BlueprintReadWrite) TEnumAsByte<TreeType> Type;
Add the following to the
Tree
constructor:auto MeshAsset = ConstructorHelpers::FObjectFinder<UStaticMesh>(TEXT("StaticMesh'/Engine/BasicShapes/Cylinder.Cylinder'")); if (MeshAsset.Object != nullptr) ...