Beginner how to Print Variable to Screen Question

I want to print to screen the camera component’s rotation values like so:


const FRotator CameraRotation = FollowCamera->GetComponentRotation();

	if (GEngine)
	{
		//Print debug message
		GEngine->AddOnScreenDebugMessage(-10, 1.f, FColor::Yellow, CameraRotation);
	}

But it says "cannot convert argument 4 from ‘const FRotator’ to ‘const FString &’

What should I use to print out the rotation values of the camera please?

Thanks

I’m basically trying to do the equivalent of this in UDK but in C++:


        GetAxes(CurrentCameraRotation, X, Y, Z);

			NewAccel.Z	= 0;

			NewAccel = PlayerInput.aForward*X + PlayerInput.aStrafe*Y;
			NewAccel = Pawn.AccelRate * Normal(NewAccel);

You just have to convert it to FString. I don’t have the engine with me to test so my apologies if this isn’t true, but I believe FRotators and FVectors have a .ToString() method.

Using the TEXT Macro is probably the easiest way:



const FRotator CameraRotation = FollowCamera->GetComponentRotation();

	if (GEngine)
	{
		//Print debug message
		GEngine->AddOnScreenDebugMessage(-10, 1.f, FColor::Yellow, FString::printf(TEXT("Rotation: %f - %f - %f"), CameraRotation.Pitch, CameraRotation.Yaw, CameraRotation.Roll));
	}


2 Likes

hmm, thanks TheJamsh but there seems to be a problem with:

I get a red wiggly line under it anyway. “Fstring has no member printf”

Also, whats the equivalent of Uncodex for C++ for Unreal?

Thanks

Try Printf. I might not have got the capitalization right.

Intellisense / VAX should fix that for you though.