Can't get a Pawn location

I can’t get a Pawn location.

Before this moment I tried a lot of cases and no one work for me.
I have a very simple Pawn and can move forward and right.
All I want just to know my present location every frame.
I was use:

GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorLocation()

and this didn’t work for me.

The result is the same location every frame. Location from where I start.

Then I try to create default third-person project and compare where I did mistake, but found that this code not work for default project AS WELL!

Now:

  1. I think, this code get PlayerController location (not pawn) that why my location doesn’t change.

  2. How can I resolve this issue? All what I need, just to get my Pawn location playing third-party player.

UPD

  1. Attach screen with logs at the start. Looks like all is fine:

![alt text][1]

  1. Here is my Pawn constructor:

    // Sets default values
    APlayerHero::APlayerHero()
    {
    // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
    PrimaryActorTick.bCanEverTick = true;
    AutoPossessPlayer = EAutoReceiveInput::Player0;
    RootComponent = CreateDefaultSubobject(TEXT(“RootComponent”));
    UCameraComponent* Camera = CreateDefaultSubobject(TEXT(“HeroCamera”));

     SceneComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("HeroSkeletMesh"));
     Camera->SetupAttachment(SceneComponent);
     Camera->SetWorldLocation(FVector(-250.f, 0.f, 250.f));
     Camera->SetWorldRotation(FRotator(-45.f, 0.f, 0.f));
     SceneComponent->SetupAttachment(RootComponent);
     RootComponent->SetWorldLocation(FVector(100.f, 100.f, 0.f));
    

    }

  2. And the last place. Code I was add into the Tick() function:

    FVector PointTwo = GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorLocation();
    UE_LOG(LogTemp, Warning, TEXT(“X = %d. Y = %d. Z = %d;”), &PointTwo.X, &PointTwo.Y, &PointTwo.Z);

ANSWER
I found the issue. Fix is very strange, but when I change this:

UE_LOG(LogTemp, Warning, TEXT("Location: x =  %d, y = %d, z = %d."), Location.X, Location.Y, Location.Z);

Into this:

UE_LOG(LogTemp, Warning, TEXT("Location: %s."), *Location.ToString());

Pawn location start working. If anybody have explanation why this work in that way, I would be really happy to hear it. Cause I spend 9 hours to resolve this problem.

  1. no, you are getting pawn location, not controller location.
  2. not sure why it is not giving current location, maybe something failed in your dereference chain. Does every step pass an IsValid check? Are there any “Accessed None” errors in the log?

How can I check it in the right way?

Did you check your logs for any warnings or errors?

I update my question with logs screenshot and part of code. May be you can get something special.

Those are very good thank you. I wonder if GetFirstPlayerController gets the same playercontroller as Player Controller 0

Sorry, I’m very new in UE4. Don’t you know some “health” method, how to debug C++ code? It’s really hard at moment to realise what going on withot debugging, but all what I found is “inject UE4.exe process into debug mode”… but this is didn’t work for me too.

One more. I output Pawn name to console and this is my pawn. All is fine.
After I output Controller name and this is “PlayerController_0”.

I found the issue and add to topic.

I am glad you fixed it. Sorry I dont know why that was happening.