Imagine I had an object that could go left, right or down. I was thinking UENUM would be ideal to hold these values, and by calculating it’s actual movement using a vector (taking in location from previous frame then adding it to the location from this current frame). Then I could just look at the vector.y and determine if it was moving left, right or down then use the enum to hold that value, by passing the enum instance into the function and assigning it the specific direction.
So this would be in the .h above the class declaration:
And as errors I get this for each line where I try to assign to EMoveDirection:
Error 1 error C2664: ‘void AtwinStickPawn::CalcDirectionFromTickVector(const FVector,EnumMoveDirection &)’ : cannot convert argument 2 from ‘TEnumAsByte<EnumMoveDirection>’ to ‘EnumMoveDirection &’
I read up the UENUM documentation in the API and I really don’t have any idea what TEnumAsByte is, is that how the enum holds it’s value as a uint8? How do I use this instead if this is more proper?
Your enum name is not really following convention. The enum type name should have the ‘E’ prefix, so:
enum class EMoveDirection: uint8
Then your variable name would become just ‘MoveDirection’.
You have EnumMoveDirection& in your declaration, and EnumMoveDirection (without the &) in your definition.
You’d be better off just returning the enum from your function rather than passing it in by reference.
Failing that, since it’s a UFUNCTION you may need to wrap your parameter/return type as TEnumAsByte< EMoveDirection >, but I wouldn’t have thought that was necessary.
I honestly have struggled to understand how to use UENUM objects because the documentation is really sparse. This is the doc I’m referring to:
This is what it says:
// Old property
UPROPERTY()
TEnumAsByte<EThing::Type> MyProperty;
// New property
UPROPERTY()
EThing MyProperty;
I actually don’t even understand what it means to wrap parameter/return type. All I know is that TEnumAsByte is a template that returns the byte corresponding to the Enum Value right?
All I meant by wrapping was to try replacing EThing with TEnumAsByte< EThing >, but as your link suggests this should no longer be needed. Although I have come across cases where a UPROPERTY is treated differently from a UFUNCTION parameter.
Did you try renaming your type as I proposed and then altering the function signature to be:
Followed by this error:
Error 1 error C4715: ‘AtwinStickPawn::CalcDirectionFromTickVector’ : not all control paths return a value h:\users\dirtrobot\my documents\unreal projects winstick\source winstick winstickpawn.cpp 375 1 twinStick
You’ve specified that your function returns a value of type EMoveDirction, but when it gets to the end of the function (ie, the if is false) - it doesn’t return anything. You need to return something there