Set vector entry by reference

Hi,

I want to modify a single entry of a vector (e.g. the x component). I attempted to do so by using the Set By-Ref Var node on the X component of the Break Vector node. However, this leaves the vector unchanged (as a simple print confirms). This way of editing single components works for custom structs but apparently not for vectors. To my understanding, vectors are structs. However, there seems to be a difference (possibly the Break Vector node returns a copy instead of a reference).


Is there a different way to modify a single component of a vector where you don’t need to pass all 3 values?

EDIT: I went ahead and wrote 3 one-liner functions in C++ that change the respective components of a vector that was passed by reference. It’s weird that this functionality is missing in the standard blueprint library. Correct me if I’m wrong:



UFUNCTION(BlueprintCallable, Category = Vector)
static void SetVectorX(float x, UPARAM(ref) FVector& vec);

void UCPPFunctionLibrary::SetVectorX(float x, FVector& vec)
{
    vec.X = x;
}

Why not just do it directly?

( this works )

Thanks for your reply. I know that it works that way, this is what I meant by “where you need to pass all 3 values”. You still have to get the other component values and pass them so a function that sets all components. I went ahead and wrote 3 one-liner functions in C++ that change the respective components of a vector that was passed by reference. It’s weird that this functionality is missing in the standard blueprint library. Correct me if I’m wrong.

I think I’m missing the point here. If you pass the vector by reference, naturally you can just change one component of it.