Working in Unreal with C++ and I was wondering if there is a way to Convert from FVector to FVector2D and vice versa as this would save me a lot of time going through my code changing it, any help would be appreciated, Thanks.
1 Like
if you read FVector documentation, you will find that there is no default convertion to FVector2D.
I think you can simply add desired convertion function as some static function to your code.
Late answer: FVector2D has a constructor that accepts an FVector reference and creates a new FVector2D from the passed in vector’s X & Y components.
FVector Vec3D(1.0f, 2.0f, 3.0f);
FVector2D Vec2D(Vec3D); // Results in FVector2D(1.0f, 2.0f)
A similar conversion (via constructor) exists the other way around as well.
9 Likes
The FVector2D constructor that accepts a FVector is very handy, cheers!
As of UE4.27.2 there’s no constructor for FVector that will take an FVector2D, so you have to break it up into floats:
FVector2D Vec2D(1.0f, 2.0f);
FVector Vec3D(Vec2D.X, Vec2D.Y, 3.0f);