Wrong output: GetClampedToMaxSize(1.0f) not working

Hello,

My problem is when I use GetClampedToMaxSize(1.0f) the function return me a vector way to far away.
So now I’m using GetClampedToSize(0.0f, 1.0f);

Just wanted to know if this is a bug or me doing something bad.

Here is my code and you got logs after:

  void UCollidingPawnMovementComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) {
    	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
    	if (!PawnOwner || !UpdatedComponent || ShouldSkipUpdate(DeltaTime)) {
    		return;
    	}
    
    	// Bug GetClamped with GetClampedToMaxSize(1.0f);
    	FVector vector = ConsumeInputVector();
    	FVector vectorClamped = vector.GetClampedToMaxSize(1.0f);
    	FVector DesiredMovementThisFrame = vectorClamped * DeltaTime * 150.0f;
    	if (!DesiredMovementThisFrame.IsNearlyZero()) {
    		UE_LOG(LogTemp, Warning, TEXT("My Vector before Clamped: %s"),
    			*vector.ToString());
    		UE_LOG(LogTemp, Warning, TEXT("My Vector After Clamped: %s"),
    			*vectorClamped.ToString());
    		FHitResult Hit;
    		SafeMoveUpdatedComponent(DesiredMovementThisFrame, UpdatedComponent->GetComponentRotation(), true, Hit);
    		if (Hit.IsValidBlockingHit()) {
    			SlideAlongSurface(DesiredMovementThisFrame, 1.f - Hit.Time, Hit.Normal, Hit);
    		}
    	}
    }

Logs:

LogTemp: Warning: My Vector before Clamped: X=1.000 Y=-0.023 Z=0.000
LogTemp: Warning: My Vector After Clamped: X=1.000 Y=-0.023 Z=0.000
LogTemp: Warning: My Vector before Clamped: X=0.977 Y=-1.023 Z=0.000
LogTemp: Warning: My Vector After Clamped: X=-23448284.000 Y=24553864.000 Z=-0.000
LogTemp: Warning: My Vector before Clamped: X=0.977 Y=-1.023 Z=0.000
LogTemp: Warning: My Vector After Clamped: X=-23448284.000 Y=24553864.000 Z=-0.00

I had the same problem but in my case it returns a zero vector. The code was working prior to upgrading my PC from Intel to AMD. Is your PC an AMD?

Try the Kismet Math Library.

// Include Header in cpp file 
#include "Kismet/KismetMathLibrary.h"

// Clamp between min and max
FVector vectorclamped = UKismetMathLibrary::ClampVectorSize(vector, 0.f, 1.f);

OR

// Clamped to MaxSize
FVector vectorclamped = UKismetMathLibrary::Vector_ClampSizeMax(vector, 1.f);