Assigning a FVector to another Fvector broken?

Been writing some code to store some info into FVectors.

//ArmsBasePostion is a FVector is declared as so in the .h file  
  UPROPERTY() 
  FVector ArmsBasePostion;

//called in my beginplay
ArmsBasePostion = FPSArms->RelativeLocation;

but this isnt working it keeps tossing an error  on left operator “=”

on the other hand

   ArmsBasePostion.X = FPSArms->RelativeLocation.X;
    ArmsBasePostion.Y = FPSArms->RelativeLocation.Y;
    ArmsBasePostion.Z = FPSArms->RelativeLocation.Z;

does work so im a little confused why the latter does not work. seems kinda dumb to have to keep breaking part any FVector to set them into another FVector.

anyone see any reason for this to not be working as it should thanks in advance

Hi,

I looked into FVector struct and it appears that it does have an operator for =, however its only available if IMPLEMENT_ASSIGNMENT_OPERATOR_MANUALLY is defined.

#ifdef IMPLEMENT_ASSIGNMENT_OPERATOR_MANUALLY
	/**
	* Copy another FVector into this one
	*
	* @param Other The other vector.
	* @return Reference to vector after copy.
	*/
	FORCEINLINE FVector& operator=(const FVector& Other);
#endif

I noticed that this is defined in the UnrealMathUtility and it’s commented out

//#define IMPLEMENT_ASSIGNMENT_OPERATOR_MANUALLY

I am not sure why this is. Maybe someone in the community can comment on this.

Either way, you can edit UnrealMathUtility and un-comment that line (Not sure what side affects this may cause), do the workaround you mentioned above, or implement a Vector adapter that extends Vector class and add this feature.

// Note: Not tested
struct FMyVector : public FVector
{
    /* Constructors 
    *
    */

    // Copy and pasted from Vector.h
    FORCEINLINE FMyVector& FMyVector::operator=(const FMyVector& Other)
    {
        this->X = Other.X;
	    this->Y = Other.Y;
	    this->Z = Other.Z;

	    return *this;
    }
}

ok ty for the info probably something they for got to undo when they where messing around in there.

No Problem. Yeah, that might be the case. I would like to know more on the design decision to wrap that operator around that define.

Anyhow, happy coding!!! :slight_smile:

You can try mutable keyword in C++. The code will look like this:-

mutable FVector ArmsBasePostion;