Defining a constant FVector

Is it possible? I would like to have something like Vector3.Forward in Unity that I can use everywhere.

You can add static members if you have full source, FVector::ZeroVector and FVector::UpVector already exist. Adding FVector::ForwardVector (1,0,0) seems like a good addition, I’ll do that now.

Thanks James.

I’m trying to add my static const members to my .h as follows:


static FVector VECTOR_FORWARD = FVector(1, 0, 0);

but this gives the compiler error “a member with an in-class initializer must be const”

When I try to do this


static const FVector VECTOR_FORWARD = FVector(1, 0, 0);

I get the compiler error “a member of type const FVector cannot have an in-class initializer”

I can however declare a const FVector like so:


const FVector VECTOR_FORWARD = FVector(1, 0, 0);

Why can’t I declare a static FVector here?

P.S.
On a side note, there is a function to get the transform of a component, but there is a typo in the name:


someComponent->GetComponenTransform();

Will this be fixed or will this just a forever legacy error? :wink:

In-Class initialization of const variables only works with integers.
You’ll get the static variable initialized correctly with these steps:

  1. Declare it as static const in the header file (in-class):
    static const FVector FORWARD;
  2. In the .cpp file write:
    const FVector MyClass::FORWARD = FVector(1,0,0);

Ah, now I understand what it means.
Thank you!

This won’t work when deploying to Android, by the way. static classes aren’t allowed