How can I avoid having to call the same function multiple times in order for it to work?

This is one big weird issue. Take rotation for example: say I have Roll rotated my character, and I want to reset the roll rotation to 0.

The normal way to go about it would be:

APlayerController* pc = Controller->CastToPlayerController();
pc->SetControlRotation(FRotator(pc->GetControlRotation().Pitch, pc->GetControlRotation().Yaw, 0.0f));

However, that won’t work. The function is executed, however no rotation takes place. So I decided to try something else:

APlayerController* pc = Controller->CastToPlayerController();

while (pc->GetControlRotation().Roll != 0.0f){
pc->SetControlRotation(FRotator(pc->GetControlRotation().Pitch, pc->GetControlRotation().Yaw, 0.0f));
}

And usually after 2-3 calls, the roll gets to be 0.

I’m using the code in the Tick method. I’m obviously not executing it every time tick gets called, but I am trying to execute it when roll !=0.
In the end, I tried debugging and went through the method calls, all looks fine except the fact that the rotation only really takes place after the second, third or forth call.

#Based on Our Forum Discussion

“I did. Also, this happens with the MoveRight method in the fps sample. In some places it works right away, in others, I have to call it multiple times in order for the character to actually move…”

I’ve never heard of anything like this

When I get weird issues, I often find it best to start over, and usually I end up with better results / find out my issue

I recommend starting a new C++ project, testing just this issue, building only required framework to test this issue

and if your issue persists, at that point you could post your test project on Answerhub to get it reviewed.

Rama