FVector default constructor returns vectors filled with random values ?

When declaring vectors like this :



FVector TestVector;


or like this :



FVector TestVector = FVector();


The resulting vector is filled with random values. Is this the expected behaviour ?
I would expect a 0 length vector.

This is FVectors default constructor.



FORCEINLINE FVector::FVector()
{}


Because it’s a standard C++ class the memory it occupies is not initialized before construction, and in this case the default constructor chooses not to initialize it either (for performance reasons I imagine), so the value of the vector is just garbage that was in that memory location previously. Use FVector TestVector(0.f) to initialize a zero vector.

Ok, thanks for your explanation The Beej. I’m a total noob with C++ and all those raw memory access “weird” behaviours are new to me.

Seems like other classes like FRotator and FQuat act the same way, so I’ll be more careful from now when calling default constructors.