[C2397] conversion from 'T' to 'float' requires a narrowing conversion

Hi all,

I hope you are all being safe and well during these crazy COVID times, looking forward to the full release of UE5! Though, at the moment I’m creating a new character controller for UE5 using C++ and all the sudden I’m running into an issue, that I did not have before in UE4.26/ UE4.27.

I’m getting the following C2397 error on the line containing :

	const float Target{ Delta.Yaw / Deltatime };

Error Log:

  ShooterAnimInstance.cpp(153): [C2397] conversion from 'T' to 'float' requires a narrowing conversion
  ShooterAnimInstance.cpp(153): [C2397] conversion from 'T' to 'const float' requires a narrowing conversion

Full snippet of the function.

void UShooterAnimInstance::Lean(float Deltatime)
	if (ShooterCharacter == nullptr) return;
	CharacterRotationLastFrame = CharacterRotation;
	CharacterRotation = ShooterCharacter->GetActorRotation();

	const FRotator Delta{ UKismetMathLibrary::NormalizedDeltaRotator(CharacterRotation, CharacterRotationLastFrame) };

	const float Target{ Delta.Yaw / Deltatime };
	const float Interp{FMath::FInterpTo(YawDelta, Target, Deltatime, 6.f)};
	YawDelta = FMath::Clamp(Interp, -90.f, 90.f);

Is there a major change in compiling UE5, compared to version 4? As this same code was running perfectly before… Or is there something I’m missing in the declaration of the variables…

Kind regards,


I guess another thing you can do is use “=” to trigger an implicit conversion when initializing with {} , cheers!

1 Like

Hey friend - just had the same issue. Was able to compile by changing all of the floats in question to doubles. just replace the word float with the word double on all the lines where the error is being thrown.

1 Like

Thanks to both of you! Going to try this out when i get home! Will let you know the outcome :blush::+1:t2:

const float Interp{FMath::FInterpTo(float(YawDelta), float(Target), float(Deltatime), 6.f)};
const double Interp{FMath::FInterpTo(YawDelta, Target, Deltatime, 6.f)};