Here’s one way to do it
ACharacter* myCharacter = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0);
myCharacter->GetActorLocation();
Here’s one way to do it
ACharacter* myCharacter = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0);
myCharacter->GetActorLocation();
I need to get the location of the first person camera from a different file in c++. I want to make an actor walk towards the player, but I don’t know how to get the player location. Any help is appreciated, thanks.
That worked perfectly. Thank You!
I know this is a two years old question but, since you can still find it when googling, I’d like to point out you can also use:
GetWorld()->GetFirstPlayerController()->GetActorLocation()
Which I personally find easier to grasp.
Hi Telmo,
I actually thought this thread was useful. I have been trying to use the above line in my C++ code in Unreal. I don’t have any issues with creating a line like the first line but as soon as I try to use GetName(), my editor crashes as I press play and it runs the GetName() or GetActorLocation() line.
Thanks for posting this. I have to sometimes run the below code to get it to work for me.
GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorLocation();