Strange FRotator Values

Hi I am getting really strange results from my FRotator results.

FRotator ACharacterFinalCharacter::CameraRotation()
{

	const FRotator cr = GetControlRotation();
	const FRotator ar = GetActorRotation();

	const float newpitch = cr.Pitch;
	const float newyaw = cr.Yaw - ar.Yaw;

	UE_LOG(LogTemp, Warning, TEXT("Yaw: %d, Pitch &d"), newyaw, newpitch );

	const FRotator truerotation = FRotator(newpitch, 0, newyaw);

	return truerotation;
}

My results are coming out “LogTemp:Warning: Yaw: -2147483648, Pitch 536870912”. It will be much appreciated if someone can explain to me why I am getting these results. Thanks.

True to log the value of cr and ar right after you create those variables. If your Controller is null it might be returning weird values like -2147483648.

The best way to check this is to log the variables. If you’re still getting errors let me know and i’ll try give you more help.

Thanks for the reply, Just tried what you suggested still getting strange results.

 FRotator ACharacterFinalCharacter::CameraRotation()
 {
 
if (Controller == NULL) return;

	const FRotator cr = GetControlRotation();
	const FRotator ar = GetActorRotation();

	UE_LOG(LogTemp, Warning, TEXT("Control = Yaw: %d, Pitch %d"), cr.Yaw, cr.Pitch);
	UE_LOG(LogTemp, Warning, TEXT("Actor = Yaw: %d, Pitch %d"), ar.Yaw, ar.Pitch);

	const float newpitch = cr.Pitch;
	const float newyaw = cr.Yaw - ar.Yaw;

	//UE_LOG(LogTemp, Warning, TEXT("Yaw: %d, Pitch %d"), newyaw, newpitch);
 
     const FRotator truerotation = FRotator(newpitch, 0, newyaw);
 
     return truerotation;
 }

Results are:

LogTemp:Warning: Control = Yaw: -1073741824, Pitch 1610612736

LogTemp:Warning: Actor = Yaw: 1073741824, Pitch 0

It looks like your Controller doesn’t have a rotation, and so you get these weird negative values. I’m not sure why this is happening, but it might pay to make sure you’ve set the controller up properly

Well this is from the default C++ Third Person example, so its all setup with a controller. I also did a test with the C++ First Person Example with the same results.

I’ll see if i can recreate this tomorrow in the engine and get back to you with a solution if I find one.

“%d” is for integers, rotation values are floats. Try changing to:

     UE_LOG(LogTemp, Warning, TEXT("Control = Yaw: %f, Pitch %f"), cr.Yaw, cr.Pitch);

That worked, Always the silly little mistakes that gets past. Anyways thanks for the replies much appreciated.

No problem.

As a reference, UE4 UE_LOG( ) should follow the same rules as this:

http://www.cplusplus.com/reference/cstdio/printf/