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"

Array of values based on an enum.

I'm trying to make a data table with an array of floats based on an enum size. Let me explain. I have damage types:

 UENUM(BlueprintType)
 enum class EDamageTypes : uint8
 {
     DT_None                            UMETA(DisplayName = "None"),
     DT_Fire                            UMETA(DisplayName = "Fire"),
     DT_Lightning                            UMETA(DisplayName = "Lightning"),
 
     ...
 };

This displays just fine in the editor and blueprints and such. I want to have what is essentially a TMap or TArray of TPairs that has the element type and a float value associated with it (for amount of damage and amount of resistances and whatnot). However, TMaps and TPairs are not supported by UPROPERTY.

 USTRUCT(BlueprintType)
 struct FTestArrayStruct : public FTableRowBase
 {
     GENERATED_USTRUCT_BODY()
 
     UPROPERTY(EditAnywhere, BlueprintReadWrite) TArray<TPair<EItemTypes, float>> testArray;
     FTestArrayStruct(){}
 };

That leads to a compilation error, as does a TMap, saying only UCLASS, USTRUCT or UENUM types are accepted.

Going forward, I see two options:

  1. Simply make it an array and add in the values as needed, 0 values for those before the index of the desired damage type. This could lead to some messy complications if put in the wrong spot and some wild errors in damage calculations.

  2. Make a USTRUCT that contains the Enum and the float value and have an array of those. But then if I wanted other enums for the same use, I'd have to make another struct for them.

Does anyone see a solution that I'm missing?

Product Version: UE 4.10
Tags:
more ▼

asked Apr 23 '16 at 06:20 AM in C++ Programming

avatar image

Yulgalminakf
73 12 17 26

avatar image Yulgalminakf Apr 23 '16 at 07:11 AM

Further testing has concluded that sadly, neither macros nor templates can accomplish what I want...

 #define MAKE_ENUM_VALUE_STRUCTURE(StructName, EnumType, EnumName, ValueType, ValueName) \
 USTRUCT(BlueprintType) \
 struct StructName \
 { \
     GENERATED_USTRUCT_BODY() \
     UPROPERTY(EditAnywhere, BlueprintReadWrite) EnumType EnumName;\
     UPROPERTY(EditAnywhere, BlueprintReadWrite) ValueType ValueName;\
     StructName(){EnumName = (EnumType)0;}\
 };
 
 MAKE_ENUM_VALUE_STRUCTURE(FTestEnumValueStruct, EItemTypes, itemType, float, amount)
 
 
 USTRUCT(BlueprintType)
 template<class EnumClass, class ValueType>
 struct FEnumStruct : public FTableRowBase
 {
     GENERATED_USTRUCT_BODY()
     UPROPERTY(EditAnywhere, BlueprintReadWrite) 
     EnumClass enumValue;
     UPROPERTY(EditAnywhere, BlueprintReadWrite) 
     ValueType value;
     //UPROPERTY(EditAnywhere, BlueprintReadWrite) TArray<TPair<EItemTypes, float>> testArray;
     FEnumStruct() {}
 };

Both of those result in compilation errors, even with the included "Filename.generated.h" file.

The macro version gives an error giving the line number of the calling of the macro, saying GENERATED_BODY() is undefined. So, I'm assuming that the unreal engine does something based off of the text in the actual file, not accounting for macros. I even tried to trick it a little by splitting up the macro into two parts, one above the GENERATED_USTRUCT_BODY() line, and one below it, so it might've recognized the line as being there without the defining body around it, but no good.

The templated version gives an error saying "Missing 'struct' in Struct declaration specifier." (I even tried switching the template and USTRUCT lines, which results in further errors).

So, I'm back to square one... making the struct by hand. Oh wells.

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first
 USTRUCT(BlueprintType)
 struct FMyEnumStruct
 {
     GENERATED_USTRUCT_BODY()
     
 public:
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "test")
     EMyEnum key;
     
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "test")
     FMyType value;
 }



 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "test")
 TArray<FMyEnumStruct> enum_struct;

You can't use your own macros with macros and structures where used this macros for reflection system. It's part of UnrealHeaderTool. You prevent the program.

And templates can't be used. Only pure USTRUCTs without anything foreign macros and templates.

You can wrote your own wrapper with TArray UPROPERTY inside to manage data type by enum value indexing.

more ▼

answered Apr 25 '16 at 01:09 PM

avatar image

broly
544 40 62 91

(comments are locked)
10|2000 characters needed characters left
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