TEnumAsByte is not intended for use with enum classes?

Is this just a UBT bug? I’m getting

TEnumAsByte is not intended for use with enum classes - please derive your enum class from uint8 instead.
note: see declaration of 'TEnumAsByte_EnumClass<true>
note: see reference to class template instantiation 'TEnumAsByte<EFNCellularReturnType>' being compiled

However, my code is as follows:

UENUM(BlueprintType)
enum class EFNCellularReturnType : uint8
{
	CellValue	 UMETA(DisplayName="CellValue"),
	NoiseLookup	 UMETA(DisplayName="NoiseLookup"),
	Distance	 UMETA(DisplayName="Distance"),
	Distance2	 UMETA(DisplayName="Distance2"),
	Distance2Add UMETA(DisplayName="Distance2Add"),
	Distance2Sub UMETA(DisplayName="Distance2Sub"),
	Distance2Mul UMETA(DisplayName="Distance2Mul"),
	Distance2Div UMETA(DisplayName="Distance2Div")
};

Functions

UFUNCTION(BlueprintCallable, meta = (DisplayName = "SetCellularReturnType", Keywords = ""), Category = "FastNoise")
	void K2_SetCellularReturnType(TEnumAsByte<EFNCellularReturnType> cellularReturnType) { SetCellularReturnType(cellularReturnType); }

	UFUNCTION(BlueprintCallable, meta = (DisplayName = "GetCellularReturnType", Keywords = ""), Category = "FastNoise")
	TEnumAsByte<EFNCellularReturnType> K2_GetCellularReturnType() const { return GetCellularReturnType(); }

I have 4 other enums in the same format.

UENUM(BlueprintType)
enum class EFNNoiseType : uint8
{
	Value		   UMETA(DisplayName="Value"),
	ValueFractal   UMETA(DisplayName="ValueFractal"),
	Perlin		   UMETA(DisplayName="Perlin"),
	PerlinFractal  UMETA(DisplayName="PerlinFractal"),
	Simplex		   UMETA(DisplayName="Simplex"),
	SimplexFractal UMETA(DisplayName="SimplexFractal"),
	Cellular	   UMETA(DisplayName="Cellular"),
	WhiteNoise	   UMETA(DisplayName="WhiteNoise"),
	Cubic		   UMETA(DisplayName="Cubic"),
	CubicFractal   UMETA(DisplayName="CubicFractal")
};

UENUM(BlueprintType)
enum class EFNInterp : uint8
{
	Linear	UMETA(DisplayName="Linear"),
	Hermite	UMETA(DisplayName="Hermite"),
	Quintic	UMETA(DisplayName="Quintic")
};

UENUM(BlueprintType)
enum class EFNFractalType : uint8
{
	FBM		   UMETA(DisplayName="FBM"),
	Billow	   UMETA(DisplayName="Billow"),
	RigidMulti UMETA(DisplayName="RigidMulti")
};

UENUM(BlueprintType)
enum class EFNCellularDistanceFunction : uint8
{
	Euclidean UMETA(DisplayName="Euclidean"),
	Manhattan UMETA(DisplayName="Manhattan"),
	Natural	  UMETA(DisplayName="Natural")
};

The generated header file seems to be where the warning originates. In the generated header of file that include the header that has the enums, it forward declares the enums as follows

enum class EFNCellularReturnType : uint8;
enum class EFNCellularDistanceFunction : uint8;
enum class EFNFractalType : uint8;
enum class EFNNoiseType : uint8;
enum class EFNInterp : uint8;

Here is te generated function calls which are generated in the same way as the rest of the enums

DECLARE_FUNCTION(execK2_GetCellularReturnType) \
	{ \
		P_FINISH; \
		P_NATIVE_BEGIN; \
		*(EFNCellularReturnType*)Z_Param__Result=this->K2_GetCellularReturnType(); \
		P_NATIVE_END; \
	} \
 \
	DECLARE_FUNCTION(execK2_SetCellularReturnType) \
	{ \
		P_GET_ENUM(EFNCellularReturnType,Z_Param_cellularReturnType); \
		P_FINISH; \
		P_NATIVE_BEGIN; \
		this->K2_SetCellularReturnType(EFNCellularReturnType(Z_Param_cellularReturnType)); \
		P_NATIVE_END; \
	} \

The project still builds but this warning is driving me mad. If anyone can see something that I can’t, please let me know. If this is a bug, please let me know. I’ve spent far too long trying to rename it, change it’s values, rename it’s values, made it the first emun, put it in the middle. No matter what I do, it is always this enum mentioned in the warnings. Any help is much appreciated.

1 Like

Hey there, afaik TEnumAsBytes is only intended for typical enums (not class enums). For class enums i believe you can use the type directly without TEnumAsBytes.

2 Likes

You are correct. It is no longer complaining after I removed TEnumAsByte on all my enums. However, the reason I added TEnumAsByte in the first place was because I got an error and it was complaining that I didn’t have it in the first place. I also had other errors that I have since resolved since that build attempt.

So everything is working now?

I’m using 4.20.2 and I was having some problems getting enums working correctly while trying to pass them as a function parameter.

Using the namespace enum technique along with the TEnumAsByte in the function parameter worked for me.

For enums that are used in replication in methods as parameters they have to be declared as TEnumAsByte or uint8 otherwise there is an error on replication.

I’m in UE5.2 and I have a UFUNCTION that takes in an enum class. When accessing the function in Blueprint, it says it’s an unrecognized type unless I use TEnumAsByte, but in doing so I get the warning:

Severity	Code	Description	Project	File	Line	Suppression State
Warning	C4996	'TEnumAsByte_EnumClass<true>': TEnumAsByte is not intended for use with enum classes - please derive your enum class from uint8 instead. Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile.	StarQuest	C:\UE_5_2_S\UnrealEngine\Engine\Source\Runtime\Core\Public\Containers\EnumAsByte.h	20	

With TEnumAsByte:
image

Without TEnumAsByte
image

I too will need replication so hopefully this won’t be a future issue.

3 Likes