How to properly insert Engine-Default Enums in FStructs

I’m trying to make an FStruct to facilitate Function Input communication for Tracing. I’m using the instructions from this page:

Here’s the .h

USTRUCT(BlueprintType) struct FMakeTraceInfo //Declaration. This Struct is used to Reduce FunctionInput Node sizes.
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HitInformation")
	ETraceTypeQuery TraceType;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HitInformation")
	bool TraceComplex;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HitInformation")
	EDrawDebugTrace DrawType;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HitInformation")
	TArray<AActor*> IgnoreArray;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HitInformation")
	bool IgnoreSelf;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HitInformation")
	FLinearColor TraceColor;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HitInformation")
	float DrawTime;

However, compiling this produces the following error:
“You cannot Use Raw Enum Name as a Type. Instead, use TEnumAsByte or a C++11 Enum Class with Explicit Underlying Type.”

If I use

TEnumAsByte <ETraceTypeQuery>  

is says illegal use (with reason), and if I use

TEnumAsByte<ETraceTypeQuery::Type>

it says that it TEnumAsByte cannot convert to ETraceTypeQuery. I’m guessing that the proper way is by including it as a C++11 type. How would I include it this way?

When compiling this struct in my 4.20 project the exact combination that worked was this:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HitInformation")
TEnumAsByte<ETraceTypeQuery> TraceType;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HitInformation")
TEnumAsByte<EDrawDebugTrace::Type> DrawType;

Both those enumerations needed to be declared as TEnumAsByte but EDrawDebugTrace is declared differently. Make sure you are including Kismet/KismetSystemLibrary.h.

3 Likes

For anyone that ever stumbles upon this question, the answer is in the following:

Look up at the Enumerator’s declaration (visit there respective Class’ page on Epic’s documentation). If it’s an Enumerator declared below c++ 11, it will have a “namespace” tag on it. That declaration is the following

TEnumAsBtye<Enum::Type>

If it is an Enum 11, it will have an UEnum declaration on it. That one is simply

TEnumAsByte<Enum>
2 Likes

Also you should add PhysicsCore to PublicDependencyModuleNames:

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "UMG", "EnhancedInput", "PhysicsCore" });