I have a UENUM I would like to use as the type for a TArray. However, attempting this produces a compiler error which I can’t wrap my head around.
This is the function in question:
void AGameCharacter::RenderTypes(TArray< EGameEquipmentDisplayType > Types, bool bShouldRender)
{
for (int i = 0; i < Types.Num(); ++i)
{
switch (Types[i])
{
case EGameEquipmentDisplayType::EQD_SmallBoots:
if (bShouldRender)
{
RenderElement(SmallBootsTextureElement, true);
}
else
{
RenderElement(SmallBootsTextureElement, false);
}
break;
//and so on for a lot of enum elements
The error which the compiler throws is this:
1>f:\unreal engine\unreal projects\GameProject 4.6\source\GameProject\GameCharacter.h(28): error C2664: 'void AGameCharacter::RenderTypes(TArray<EGameEquipmentDisplayType,FDefaultAllocator>,bool)' : cannot convert argument 1 from 'TArray<TEnumAsByte<EGameEquipmentDisplayType>,FDefaultAllocator>' to 'TArray<EGameEquipmentDisplayType,FDefaultAllocator>'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>F:\Unreal Engine\Unreal Projects\GameProject 4.6\Source\GameProject\GameCharacter.h(28): error C2664: 'void AGameCharacter::RenderTypes(TArray<EGameEquipmentDisplayType,FDefaultAllocator>,bool)' : cannot convert argument 1 from 'TArray<TEnumAsByte<EGameEquipmentDisplayType>,FDefaultAllocator>' to 'TArray<EGameEquipmentDisplayType,FDefaultAllocator>'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
I’m not getting anywhere with this. Any help will be greatly appreciated.
Unfortunately, I can’t directly select one of the enum types, as I need the array to be able to hold different values (such as EQD_SmallTrousers and EQD_PuffySleeves) at the same time.
Make sure you have included the file containing the UENUM
2. Try changing TArray for TArray<TEnumAsByte>
3. If all not work, use uint8 in your array and cast back to EGameEquipmentDisplayType.
Make sure you have included the file containing the UENUM
2. Try changing TArray for TArray<TEnumAsByte>
3. If all not work, use uint8 in your array and cast back to EGameEquipmentDisplayType.
this sounds like it would be alot of work to add new entries to that enum, you would have to update its rendering switch/case entry as well.
why not just use an array of structs, where each struct contains a name and a reference to a texture element? then your render code could be generic, so it doesn’t need to be updated for every entry.