Difference between namespace and enum?

Hello,

I’m currently working with custom enums in my project and I was wondering what is the difference between two ways of declaring them. Is one better/easier to use than the other one ?

For example :

UENUM()
namespace ETransitionGetter
{
	enum Type
	{
		AnimationAsset_GetCurrentTime,
		AnimationAsset_GetLength,
		AnimationAsset_GetCurrentTimeFraction,
		AnimationAsset_GetTimeFromEnd,
		AnimationAsset_GetTimeFromEndFraction,
		CurrentState_ElapsedTime,
		CurrentState_GetBlendWeight,
		CurrentTransitionDuration,
		ArbitraryState_GetBlendWeight
	};
}

and

UENUM()
enum ERadialImpulseFalloff
{
	/** Impulse is a constant strength, up to the limit of its range. */
	RIF_Constant,
	/** Impulse should get linearly weaker the further from origin. */
	RIF_Linear,
	RIF_MAX,
};

What is the purpose of the “namespace” keyword here ? What does mean the “Type” keyword then ?

I see, thanks ! :slight_smile:

The ‘namespace’ method is the more ‘modern’ one and they way we try to add new enums. The advantage is that enums appear as e.g. ‘ETransitionGetter::CurrentState_GetBlendWeight’, which is clearer to read (the enum type is right in the name) and means enum entries do not have to be globally unique. We didn’t go through and rework existing enums because the benefits were not worth the risks.

These days you might also see C++11 style enum classes (although I don’t think these will work with the UHT UENUM declaration).

enum class EMyEnum
{
    Entry1,
    Entry2,
};

Accessing these uses the same syntax as the namespace version (EMyEnum::Entry1), but has the advantage of being strongly typed. C++11 - Wikipedia

Hey James,

Is this still the case? Or has epic transitioned to using enum class for all new enums?