Enums, structures outside classes in C++

Hello. Maybe it’s a stupid question but i’m beginner and this is a confusing moment. Can i create general structures, enums, etc outside classes which i create to use them in different? E.g., in blueprints we create enums in the menu and after that add them to different classes and use with different values inside. Is it possible in C++? Everybody tells how to add components, create str, enums only in classrs, but not about it.

Create a separate class derived from UserDefinedEnum, and create all your enums in there. But you’ll have to explicitly #include this class in every class where you want to use the enums.

1 Like

Yes you can. You can follow basic documentation of c++ on how to declare structs and enums. to use structs or enums with Blueprint you have to add a macro above the declaration like UENUM or USTRUCT like how you do it with UCLASS. Like this:

UENUM(BlueprintType)
enum class E_PreviousNextDirections : uint8 {
	Previous,
	Next,
};

The BlueprintType specifier means it can be used with Blueprint.

Class Specifiers | Unreal Engine 4.27 Documentation

C# | Data Types - GeeksforGeeks

1 Like