Hi. How do i create a ENUM that i can use in blueprint AND C++. And how do i use that enum in a function in another class ?
You can use an Enum like this:
UENUM(BlueprintType)
enum class EMyCustomEnum : uint8
{
EMCE_Option1 UMETA(DisplayName = "Option 1"),
EMCE_Option2 UMETA(DisplayName = "Option 2"),
EMCE_Option3 UMETA(DisplayName = "Option 3")
};
UPROPERTY(EditAnywhere, Category = "Your Category Name")
EMyCustomEnum MyCustomEnum;
If you want to access this Enum in another class inside a function then first you need a reference to the class with this Enum. After that you can simply access it. For example if the above Enum is in a class called MyCustomClass then in MyAnotherCustomClass you will create a function like this:
// header (.h)
UPROPERTY()
AMyCustomClass* MyCustomClass;
// source (.cpp)
void AMyAnotherCustomClass::AccessEnumFunction()
{
if (MyCustomClass != nullptr)
{
// Access enum like this
// MyCustomClass->MyCustom;
}
}
Then you need to include that class with the enum in your another class. For example, inside MyAnotherClassName you need to include MyCustomClass.
// header
#include "MyCustomClass.h"
I’ve never tried to add an enum from another class as a parameter for another class. In case you bump into any error please see the DependsOn class specifier.
Not inside a function inside the parameters sorry about that! Like this:
void MYFUNC(MYENUMINANOTHERCLASS enum);
Thanks ! The Include was the thing ive missed!