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:
-
I think, this code get PlayerController location (not pawn) that why my location doesn’t change.
-
How can I resolve this issue? All what I need, just to get my Pawn location playing third-party player.
UPD
- Attach screen with logs at the start. Looks like all is fine:
![alt text][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));
}
-
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.