How to pass constant values from my plugin c++ class to bluprint?

I’m developing an unreal engine plugin that has some functions and I wanna limit my function input variables values. For exp my function gets an integer as rotation_mode. It should be 0 or 1 or 2 and I prefer that developers use PORTRAIT,LANDSCAPE,AUTO instead of numbers. The Enums would be a good solution as I researched but it can be use only in global section and I can’t use it inside “public:” section of main “.h” file of my plugin. Is here a better solution for my situation?

enums should work in private, you declere enum outside of class and use it as type. Can you paste your code? what error do you get when you try to put enum on private?

You should be able to use the enum in blueprint globally if you preface it with the BlueprintType specificer in c++ like so.

UENUM(BlueprintType)
enum class ESample : uint8
{
	Option1 = 0,
	Option2 = 1,
	Option3 = 45
};

I placed this in my a blueprint function library within my plugin, but it should work in any header file so long as it is placed above the class declaration. The enum itself will be made available to any class in blueprint and any class includes the appropriate header file in c++.

Here’s an example of a way to use it in c++ that adds it to the inspector in a blueprint class that inherits from the class.

public:	
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Test")
	ESample Sample = ESample::Option1;

This is a public variable in my c++ class that I had my character inherit from. Doing this creates a section on the details pane of the character (but could be used in a GameMode, GameInstance, etc…) that looks like this:

224199-ue4editor-2017-12-17-21-50-02.png

Making this a variable allows you do several things with it, including converting the value to an int:

Back in c++ you can create blueprint exposed functions that take the enum value as input parameter to limit what the user of the blueprint node can enter and so on.

I believe this is what you’re after, but please let me know if I missed anything. Another way to go about it would to be use a TMap, where you could assign the value 0 to the sting value “Portrtait” and so on… Still, I beleive an enum is the way to go, as it’s more straight forward and only allows for predefined values, making it harder for someone to muck up.