Having trouble with enum syntax

You need a comma to separate entries in the enum.

UENUM()
 enum class ECharacterState : uint8{
     Locomotion,
     Attacking,
     Grabbing,
     Dodging,
 };

I’m trying to create a new enum to keep track of the player’s current state, and I’m having trouble with the definition:

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class LEARNINGPROJECT_API ULexicon : public UActorComponent
{
	GENERATED_BODY()

public:	

	// Called when the game starts
	virtual void BeginPlay() override;
	
	// Called every frame
	virtual void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) override;	
};

UENUM()
enum class ECharacterState : uint8{
	Locomotion
	Attacking
	Grabbing
	Dodging
};

This produces boatloads of syntax errors on compile, so I assume I’m doing something slightly wrong, but it looks identical to my example in A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums , the only difference is the lack of BlueprintType in the UENUM(), which is unnecessary since I’m only using this enum in code.

Oh hey, that fixes everything, thank you!!

I’m curious, what’s the purpose of the uint8 designation to the right of the enum’s name? Is that just specifying how it’s hashed or something?

The type to the right of the enum class declaration defines how large the enum type should be.

The Unreal Header Tool (UHT) only supports enums that are 1-byte, so the uint8 designation ensures that your enum is 1-byte. Prior to C++11 and UHT support for enum class, we used to enforce this by using TEnumAsByte when declaring enum properties - you may still see this in existing engine code.

That’s super-helpful, thank you very much for the clarification :slight_smile: