Exposing C++ Constants to Blueprints In Unreal

I am looking for some way to let a blueprint have access to predefined constants that I will create in an AActor class.

I essentially want them to keep my code clean in my blueprints. For instance, in strict code, I am able to use preprocessor macros like this:

#define kDirectionUp 0
#define kDirectionDown 1

Or I can just use constants:

const int32 kDirectionUp = 0;
const int32 kDirectionDown = 1;

Then later on, instead of having to remember a number (0…3) and what they all refer to, I can just type

doSomething(kDirectionUp);

This is not a huge deal for this particular range, but I have others that have about 8 different numbers that all represent a different value. That’d be a pain to deal with in blueprints, and not to mention difficult to debug and difficult for any other programmer to know what each of these mystic numbers mean.

I want to replicate this behavior in blueprints so that I can just plug a constant in in some places, rather than having to remember a list of 12 or so integer key numbers.


The idea is for them to be static, so UPROPERTYs will not work here (as far as I know).

My only ideas so far have been to create functions for each constant that I can call that simply return the number in question, but this isn’t the prettiest solution, not to mention they also need to have parameters of some kind, which would just have to be dummies in this case. That’s ugly.

Is there any way at all for me to expose constant values to Blueprints in Unreal to accomplish this? They are all going to be integers in this case, but solutions that work for other data types are extremely appreciated.

After doing some more digging, I found that Unreal Blueprints support enumeration!

This appears to have worked for me. Having to convert from integers to enumerated values via screening is less than ideal, but it is much cleaner than having to have a series of branch statements to check integer values.

UENUM(BlueprintType)
enum class EDirection : uint8
{
	D_Up = 0	UMETA(DisplayName = "Up"),
	D_Right = 1	UMETA(DisplayName = "Right"),
	D_Down = 2	UMETA(DisplayName = "Down"),
	D_Left = 3	UMETA(DisplayName = "Left")
};