x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

C++ Enum questions

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 ?

Product Version: UE 4.11
Tags:
more ▼

asked Apr 13 '16 at 12:15 PM in C++ Programming

avatar image

Gunschlinger
116 16 23 41

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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;
     }
 }



more ▼

answered Apr 13 '16 at 12:26 PM

avatar image

ryanjon2040
1.6k 56 43 93

avatar image Gunschlinger Apr 13 '16 at 12:29 PM

Not inside a function inside the parameters sorry about that! Like this: void MYFUNC(MYENUMINANOTHERCLASS enum);

avatar image ryanjon2040 Apr 13 '16 at 12:37 PM

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.

avatar image Gunschlinger Apr 13 '16 at 03:07 PM

Thanks ! The Include was the thing ive missed!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question