TArray or static array with UENUM

Hi,

assume that We have an enum:

/** keep in sync with ShooterImpactEffect */
UENUM()
namespace EShooterPhysMaterialType
{
	enum Type
	{
		Unknown,
		Concrete,
		Dirt,
		Water,
		Metal,
		Wood,
		Grass,
		Glass,
		Flesh,
       MAX,
	};
}

I want to declare TArray or static array of structs with indices named same as enum elements. Anyone know how to do this ?

UPROPERTY(EditAnywhere, Category = Impact)
FImpactData ImpactDataArray[EShooterPhysMaterialType::MAX];

Doesn’t work :frowning:

Thanks in advance

Pierdek

What is the error you’re seeing? I’ve just tried the following and found that it complies as I’d expect.

UENUM()
namespace EShooterPhysMaterialType
{
	enum Type
	{
		Unknown,
		Concrete,
		Dirt,
		Water,
		Metal,
		Wood,
		Grass,
		Glass,
		Flesh,
		MAX,
	};
}

USTRUCT()
struct FImpactData
{
	GENERATED_USTRUCT_BODY()
};

UCLASS()
class UMyObject : public UObject
{
	GENERATED_UCLASS_BODY()

	UPROPERTY(EditAnywhere, Category = Impact)
	FImpactData ImpactDataArray[EShooterPhysMaterialType::MAX];
};

I presume FImpactData is a USTRUCT? (it has to be a USTRUCT or UOBJECT to be usable with a UPROPERTY).

Well, You didn’t understood me correctly, I don’t have any errors with my code.

Look on the attached screenshot. I’m searching for a way how to setup enum and array to visualise array indices as enum elements:
0 → Unknown

1 → Concrete

2 → Dirt

That looks like an TArray of FImpactData? Am I correct in thinking that?

A fixed sized array from an enum should give you the names you want, but a TArray will show indices because it’s dynamicly sized, so doesn’t really know that they correspond to the enum values.

This is what my code above produces (running on 4.2 with some test properties added to FImpactData).

8529-ue4_fixedsizedarrayfromenum.png

Nice, it is working, thanks you very much :slight_smile: I can live without dynamic arrays.

Pierdek

This used to work fine, but not anymore… I don’t know since when.
Now, I only get the numerical indices instead of the Enum’s text in the property window.
Is something broken with that feature or am I missing something ?

It is working in 4.6.1, what is your engine version?

Ooops… just figured it out :
UENUM()
enum EFM_Faction
{
WARF,
TFC,
HORD,
WRECKHEADZ,
CRIMSONTEARS,
MAX
};

    UCLASS()
    class AIRWARU4_API AFactionManager : public AActor
    {
    	GENERATED_UCLASS_BODY()
    	
    UPROPERTY(EditAnywhere)		int32	FactionTab[EFM_Faction::MAX];	
    	
    #if WITH_EDITORONLY_DATA
    	// Reference to sprite visualization component
    	UPROPERTY()
    	UBillboardComponent		*SpriteComponent;
    #endif // WITH_EDITORONLY_DATA
    };

this code gives :

25259-enum1.jpg

And the following :

UENUM()
enum EFM_Faction
{
	WARF,
	TFC,
	HORD,
	WRECKHEADZ,
	CRIMSONTEARS,
	EFM_MAX
};

UCLASS()
class AIRWARU4_API AFactionManager : public AActor
{
	GENERATED_UCLASS_BODY()
	
UPROPERTY(EditAnywhere)		int32	FactionTab[EFM_MAX];	
	
#if WITH_EDITORONLY_DATA
	// Reference to sprite visualization component
	UPROPERTY()
	UBillboardComponent		*SpriteComponent;
#endif // WITH_EDITORONLY_DATA
};

Gives:

25260-enum2.jpg

… wich is fine.

For anyone too lazy to whip out a diff tool: the difference was using EFM_MAX instead of EFM_Faction::MAX.

Worth noting that this also doesn’t work if you use static_cast eg:

FSomeStruct ArrayData[static_cast(EEnum::Max)];