Pierdek
(Pierdek)
June 16, 2014, 8:01pm
1
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
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).
Pierdek
(Pierdek)
June 16, 2014, 9:44pm
3
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).
Pierdek
(Pierdek)
June 17, 2014, 6:20am
5
Nice, it is working, thanks you very much I can live without dynamic arrays.
Pierdek
elliotek
(elliotek)
December 31, 2014, 3:16pm
6
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 ?
Pierdek
(Pierdek)
December 31, 2014, 3:18pm
7
It is working in 4.6.1, what is your engine version?
elliotek
(elliotek)
December 31, 2014, 3:40pm
8
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 :
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:
… wich is fine.
idbrii
(idbrii)
November 25, 2015, 6:40pm
9
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)];