In Mike’s example, he used GetWorld()->GetFirstPlayerController() in order to find the player controller. However, this will only work in a single player game if I’m not mistaken and also requires us to #include Engine/World.h
Before Mike walked through the solution, this is what I came up with:
// Called every frame
void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
FVector PlayerViewPointLocation = GetOwner()->GetActorForwardVector();
FRotator PlayerViewPointRotation = GetOwner()->GetActorRotation();
GetOwner()->GetInstigatorController()->GetPlayerViewPoint(OUT PlayerViewPointLocation, OUT PlayerViewPointRotation);
UE_LOG(LogTemp, Warning, TEXT("Location: %s"), *PlayerViewPointLocation.ToString());
UE_LOG(LogTemp, Warning, TEXT("Rotation: %s"), *PlayerViewPointRotation.ToString());
}
But in this case, we can simply reference the owner of our Grabber component and get the Controller directly from it, allowing for the code to work for multiplayer functionality and not have to #include extra references. It seems to work in my test, is there something I’m missing that makes Top-Down referencing here better? Thank you for your time!