AclinxRL
(AclinxRL)
1
Hello. I’m trying to recreate this blueprint function in c++.
The problem is I’m getting an error when converting back to the enum IconStyle
void UGamePlay_Settings::RightArrowIconStyle(USave_Gameplay* IconStyle)
{
uint8 byte = (uint8)IconStyle;
int X = (int)byte;
X += 1;
FMath::Clamp(X, 0, 2);
uint8 byte2 = (uint8)X;
IconStyle = (IconStyle)byte2; //error
}
Anyone Know what’s Wrong with this?
GarnerP57
(GarnerP57)
2
You are not using C++ but C style cast and you can’t use a parameter as a type when casting.
Instead of all this you should use C++ casts and you can also avoid all the hardcoded numbers.
EIconStyle UGamePlay_Settings::RightArrowIconStyle()
{
TrySetSelectedIconStyle(true);
return SelectedIconStyle;
}
EIconStyle UGamePlay_Settings::LeftArrowIconStyle()
{
TrySetSelectedIconStyle(false);
return SelectedIconStyle;
}
void UGamePlay_Settings::TrySetSelectedIconStyle(const bool IncrementIndex)
{
const int8 AddIndex = IncrementIndex ? 1 : -1;
const UEnum* Enum = StaticEnum<EIconStyle>();
const uint8 CurrentValue = static_cast<uint8>(SelectedIconStyle);
if (!IncrementIndex || CurrentValue != Enum->GetMaxEnumValue())
{
const int32 CurrentIndex = Enum->GetIndexByValue(CurrentValue);
const int32 NewIndex = CurrentIndex + AddIndex;
if (NewIndex < 0) { return; }
const int64 NewValue = Enum->GetValueByIndex(NewIndex);
SelectedIconStyle = static_cast<EIconStyle>(NewValue);
}
}
SelectedIconStyle should be a member variable of type EIconStyle