Why is my UENUM undefined?

Character.h

public:
	ASurvivalArenaCharacter();

	UENUM()
	enum class EInventorySlot : uint8
	{
		Hands,
	};

Weapon_Base.h

#include "Character.h"

    EInventorySlot Slot; //compiler says undefined

Screenshots:


You declared your type within the class scope of ASurvivalArenaCharacter. If you want to access it from outside of that namespace, you must refer to it as ASurvivalArenaCharacter::EInventorySlot, like this:

 ASurvivalArenaCharacter::EInventorySlot Slot;

While this is valid C++ on its own, there is a caveat that UENUMs do not work correctly if not declared in global scope (at least, this used to be true, and I’m assuming it’s still there). You should move your UENUM declaration to the top of your SurvivalArenaCharacter.h file, just after the #include statements but before the UCLASS declaration of your ASurvivalCharacter class begins.

UENUM()
enum class EInventorySlot : uint8
{
	Hands,
};

UCLASS(config=Game)
class ASurvivalArenaCharacter : public ACharacter
{
	...

And then you can safely refer to your enum type as simply EInventorySlot, without needing the ASurvivalArenaCharacter:: namespace prefix.

My unreal header build tool would crash if I used

ASurvivalArenaCharacter::EInventorySlot Slot;

As a parameter for one of my functions.Thanks for letting me know about the other method, I was wondering how other projects were able to do just what you described. Very helpful!