What is proper way to make Enum for BP and C++ both

I see how to make a User Defined Enum in the Editor, and in C++, but, how do you reference them from the other. THey don’t appear to be connected.

How do you set up an enum that will be used in both C++ and in Blueprints.

Thanks,

Dear Mike,

Great question!

I had fun figuring this one out!

I have posted a tutorial on the forum that shows you exactly how to create your own Enums for C++ and BP Graph use,

Please note that this tutorial and pictures below are for creating an Enum that can be used in the C++ and in BP graphs.

Specifically I made sure that the C++ created Enum would work with Switch on Enum BP Graph Node.

:slight_smile:

#Tutorial Link:

http://forums.epicgames.com/threads/972861-33-TUTORIALS-C-for-UE4-gt-gt-New-Create-Your-Own-Enums-for-Use-with-C-and-BP-Graphs?p=31745006&viewfull=1#post31745006

Pictures from Tutorial:


#C++ Code From Tutorial

UENUM(BlueprintType)		//"BlueprintType" is essential specifier
namespace EVictoryEnum
{
	//256 entries max
	enum Type
	{
		VE_Dance 	UMETA(DisplayName="Dance"),
		VE_Rain 		UMETA(DisplayName="Rain"),
		VE_Song		UMETA(DisplayName="Song"),
		
		//~~~
		
		//256th entry
		VE_Max		UMETA(Hidden),
	};
}

UCLASS()
class YourClass : public YourSuperClass
{
	GENERATED_UCLASS_BODY()
	
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Enum)
	TEnumAsByte VictoryEnum;

	//Rest of Class Code
};

C++ Testing the Value in the C++

//YourClass.CPP
if(VictoryEnum == EVictoryEnum::VE_Dance)
{
	VictoryEnum = EVictoryEnum::VE_Song;
}
else
{
	VictoryEnum = EVictoryEnum::VE_Rain;
}

Enjoy!

Rama

PS: if my tutorial answers your question please mark this thread as fully resolved.

I look forward to seeing the unfolding of your cat game!

Thanks, this is great.

Did it work for you?

I added some code for checking and setting values in the C++

If my tutorial answers your question please mark the checkmark by my answer so everyone else knows this issue is resolved

(UDN Epic Crew wont be doing that automatically for a couple weeks)

C++ Testing the Value in the C++

//YourClass.CPP
if(VictoryEnum == EVictoryEnum::VE_Dance)
{
	VictoryEnum = EVictoryEnum::VE_Song;
}
else
{
	VictoryEnum = EVictoryEnum::VE_Rain;
}

Actually I have a question regarding the enums. What about if you use the enum to make separate leveling objects like this.

Enum EAbilityLevel
{
     A_One,
     A_Two,
     A_Three
};

EAbilityLevel N_Level = A_One; 
EAbilityLevel W_Level = A_One;

I would want to make each of those enum objects visible in blueprint from my C++. Was curious if that was possible.

Hi @CHADALAK1,

I am going to close this post due to its age. If you would like some additional help on this topic, please post a new question.