Can't share UENUM across classes

Hello, I’m trying to put several enums into a separate namespace/header file so I can include the header in other classes and share the enum.

Enum File:

 #pragma once
 #include "CoreMinimal.h"

    namespace MyEnumsNamespace
    {
        UENUM(BlueprintType)
        enum class EPrimaryCategories : uint8
        {
            None UMETA(DisplayName = "None"),
            Powers UMETA(DisplayName = "Powers"),
        };
    }
      
    class MYPROJECT_API HUDEnums
    {
    public:
    	HUDEnums();
    	~HUDEnums();
    };

Class trying to use them:

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "MyProject.h"
#include "HUDEnums.h"
#include "MainGamePlayerController.generated.h"

UCLASS()
class MYPROJECT_API AMainGamePlayerController : public APlayerController
{
	GENERATED_BODY()
	
public:
    AMainGamePlayerController(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());

protected:
    UFUNCTION(BlueprintCallable)
    void SelectPrimaryCategory(MyEnumsNamespace::EPrimaryCategories Category);
}

The error I get is: Cannot find class ‘’, to resolve delegate ‘EPrimaryCategories’

This is what I know / have tried:

  1. If I remove the UENUM and UFUNCTION tags, everything works fine, though that is not an option because I need to expose this function to BPs.
  2. If I were to move this enum into the same class (minus the namespace) it would work fine.

Figured it out, UENUM’s can’t be in a namespace.

The reason its working without the UENUM() and UFUNCTION() decorators is because the reflection system in unreal can only “see” two types of enum declarations. Either:

UENUM()
namespace EExampleEnum
{
    enum Type
    {
         value1,
         value2
    }
}

OR

UENUM() //this can be blueprinttype
enum class EExampleEnum : uint8
{
   value1,
   value2
}

My recomendation is to ALWAYS use the second type, using an scoped enum is always better. And by the look of your own code you do not need the namespace to begin with (enums do not need a namespace to be declared).
Hope it helps. Make it a great day!