ENUM_CLASS_FLAGS breaks when used with UFUNCTION or UPROPERTY

I’m seeing weird behavior where bit flags enum defined using the ENUM_CLASS_FLAGS macro break when used as a UPROPERTY or as the return value for a UFUNCTION.

Take the following class, for example. This compiles fine, like this:

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "GestureRecognizerComponent.h"
#include "SwipeGestureRecognizer.generated.h"



enum class EGestureSwipeType : uint8
{
	SwipeNone				= 0			UMETA(DisplayName="No Swipes"),
	SwipeLeft				= 0x1		UMETA(DisplayName="Swipe Left"),
	SwipeRight				= 0x2		UMETA(DisplayName="Swipe Right"),
	SwipeUp					= 0x4		UMETA(DisplayName="Swipe Up"),
	SwipeDown               = 0x8		UMETA(DisplayName="Swipe Down"),
	SwipeDiagonal			= 0x10		UMETA(DisplayName="Swipe Diagonal")
};

ENUM_CLASS_FLAGS(EGestureSwipeType);

// Common bitflag combinations
#define SwipeHorizontal (SwipeLeft | SwipeRight)
#define SwipeVertical (SwipeUp | SwipeDown)
#define SwipeClassic (SwipeHorizontal | SwipeVertical)




/**
 * A gesture recognizer component to detect swipes
 */
UCLASS(meta=(BlueprintSpawnableComponent))
class GESTURERECOGNIZER_API USwipeGestureRecognizer : public UGestureRecognizerComponent
{
	GENERATED_BODY()
	USwipeGestureRecognizer();
	
public:
	
	/** The minimum length of a swipe to register as a swipe */
	UPROPERTY(EditAnywhere, Category=Gestures)
	float MinimumSwipeDistance;
	
	/** How far the gesture can travel in the 'wrong' direction (e.g. up/down for a horizontal swipe) before the gesture no longer counts as a swipe. Only use for up/down/left/right, not diagonal */
	UPROPERTY(EditAnywhere, Category=Gestures)
	float Tolerance;
	
	/** Which swipes to detect (bitflag) */
	//UPROPERTY(EditAnywhere, Category=Gestures)
	EGestureSwipeType SupportedSwipeTypes;
	
	//UFUNCTION(BlueprintCallable, Category=Gestures)
	EGestureSwipeType GetSupportedSwipeTypes();
	
	
protected:
	virtual void InitializeComponent() override;
	virtual void DetectGestures(float DeltaTime) override;
	virtual void GestureFinished() override;
	virtual void ResetGesture(void) override;
	
};

But, if I uncomment the UFUNCTION or UPROPERTY line in front of either usage of EGestureSwipeType, I get compiler errors out with the following message:

/Users//Documents/Unreal Projects/GestureRecognizer/Source/GestureRecognizer/SwipeGestureRecognizer.h(51) : Error: In SwipeGestureRecognizer: Unrecognized type 'EGestureSwipeType'

Error: Failed to generate code for GestureRecognizerEditor - error code: OtherCompilationError (2)
UnrealHeaderTool failed for target 'GestureRecognizerEditor' (platform: Mac, module info: /Users//Documents/Unreal Projects/GestureRecognizer/Intermediate/Build/Mac/GestureRecognizerEditor/DebugGame/UnrealHeaderTool.manifest).
Command /Users/Shared/UnrealEngine/4.7/Engine/Build/BatchFiles/Mac/RocketBuild.sh failed with exit code 2

If you’re interested in trying it out, you can find the sample project here:

link text

This is happening on a Mac. I have not tested on a Windows machine to see if the behavior is the same.

Those macros are markers from UnrealHeaderTool (the tool that throw you a error) that generates header files which contains information about code elements (classes, functions, varables etc.) which during execution is used for reflection system, without that engine would be not aware of specific function etc (as code compiled to machine code has no information about them). This system supports only types that are supported by reflection system and only types that visible to it… your enum is not as you forgot add UENUM() before it’s declaration, thats why UHT gives you “Unrecognized type” error because without that macro he is not aware of your enum existence.

Hey -

You should be able to add TEnumAsByte with the EnumType in angle brackets so that it will be recognized by the UPROPERTY() macro. Here is the general syntax:

UPROPERTY()
TEnumAsByte<EnumName> VarName;