Get pointer to data from FVector (like

In std::vector you have function that returns a type* pointer to the start of the vector.

You can use that in combination with vector.size() for functions requiring dynamic arrays like:

void function(const float* data, int arraySize)

so you can call:

function(, vector.size())

Is there any way I can do this with FVector, without having to convert FVector to std::vector and back again?

TArray (which analogous to std::vector) has a GetData method.

So, it would be

function(MyArray.GetData(), MyArray.Num());

In C++ you can… cast.

FVector myVector(cool values);
float *pFloat = (float*)&myVector;
int floatCount = sizeof(FVector) / sizeof(float);

Not the most elegant thing to do in general but probably fairly safe here.

I believe C++ defines that elements within a single private/protected/public block will be in order. As FVector doesn’t have virtual functions you don’t have to worry about a pointer (typically at the start of an object, but doesn’t have to be).

struct FVector 

	/** Vector's X component. */
	float X;

	/** Vector's Y component. */
	float Y;

	/** Vector's Z component. */
	float Z;

Given that X is the first element you could also go with:

float *pFloat = &myVector.X;

pFloat[1] will be Y, [2] will be Z.

If you want the same functionality as an std::vector you want to be using a TArray. An FVector is a 3D point used for math (X, Y, Z).

TArray has a .GetData() as well as a .Num()