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"

Exposing C++ Constants to Blueprints In Unreal

I am looking for some way to let a blueprint have access to predefined constants that I will create in an AActor class.

I essentially want them to keep my code clean in my blueprints. For instance, in strict code, I am able to use preprocessor macros like this:

 #define kDirectionUp 0
 #define kDirectionDown 1

Or I can just use constants:

 const int32 kDirectionUp = 0;
 const int32 kDirectionDown = 1;

Then later on, instead of having to remember a number (0..3) and what they all refer to, I can just type

 doSomething(kDirectionUp);

This is not a huge deal for this particular range, but I have others that have about 8 different numbers that all represent a different value. That'd be a pain to deal with in blueprints, and not to mention difficult to debug and difficult for any other programmer to know what each of these mystic numbers mean.

I want to replicate this behavior in blueprints so that I can just plug a constant in in some places, rather than having to remember a list of 12 or so integer key numbers.


The idea is for them to be static, so UPROPERTYs will not work here (as far as I know).

My only ideas so far have been to create functions for each constant that I can call that simply return the number in question, but this isn't the prettiest solution, not to mention they also need to have parameters of some kind, which would just have to be dummies in this case. That's ugly.

Is there any way at all for me to expose constant values to Blueprints in Unreal to accomplish this? They are all going to be integers in this case, but solutions that work for other data types are extremely appreciated.

Product Version: UE 4.8
Tags:
more ▼

asked Jul 13 '15 at 09:51 AM in Blueprint Scripting

avatar image

MNP_David
107 16 24 28

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

1 answer: sort voted first

After doing some more digging, I found that Unreal Blueprints support enumeration!

This appears to have worked for me. Having to convert from integers to enumerated values via screening is less than ideal, but it is much cleaner than having to have a series of branch statements to check integer values.

 UENUM(BlueprintType)
 enum class EDirection : uint8
 {
     D_Up = 0    UMETA(DisplayName = "Up"),
     D_Right = 1    UMETA(DisplayName = "Right"),
     D_Down = 2    UMETA(DisplayName = "Down"),
     D_Left = 3    UMETA(DisplayName = "Left")
 };
more ▼

answered Jul 13 '15 at 10:31 AM

avatar image

MNP_David
107 16 24 28

(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