GetActorLocation returns (0, 0, 0) if it is called from a delegate function to an Action event


I have a class than inherits from a APawn.

Inside the BeginPlay method I call GetActorLocation() and it returns its location (-820, 0, 500).

Then, when the user press a key, in a delegate function to an Action defined in the project settings, I call again GetActorLocation() and it returns (0, 0, 0).

By the way, the BeginPlay method and the delegate function (AMyPawn::ZoomIn) are both defined in the same class.

void AMyPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)

InputComponent->BindAction("ZoomIn", IE_Pressed, this, &AMyPawn::ZoomIn);


I don’t know why it happens, but it can be because the AMyPawn::ZoomIn is called as a delegate.

Why does GetActorLocation() return (0, 0, 0)?

It’s not because of a delegate for sure, it doesn’t matter how a function is called.
Set a looping timer on BeginPlay() and show GetActorLocation() every second. Wait and see what location it returns for a few ticks. Then press your ZoomIn input. What location will be returned? If it’s (0,0,0) again, does the location value change for the timer tick too?

@Tuerer I think the problem is with Visual Studio Debugger. I’ve added a UE_LOG and it prints the correct actor location.

Maybe, I don’t have to use the debugger inside these kind of methods.