In SimpleShooter video “Refactoring PullTrigger” at minute 6:38, we made a function called “GetOwnerController and assigned it to OwnerController”.
AController* OwnerController = GetOwnerController();
However, a few lines later we assign OwnerController as a different value.
OwnerController->GetPlayerViewPoint(OUT CameraLocation, OUT CameraRotation);
The first one seems to be about getting APawn and returning it into an AController type. Are we using the OwnerController for two different things in this case since it is set = to two different things?
Full section of code is:
bool ARifleBase::GunTrace(FHitResult& BulletHit, FVector& ShotDirection)
{
AController* OwnerController = GetOwnerController();
if (!OwnerController) { return false; }
FVector CameraLocation;
FRotator CameraRotation;
OwnerController->GetPlayerViewPoint(OUT CameraLocation, OUT CameraRotation);
ShotDirection = -CameraRotation.Vector();
FVector BulletEnd = CameraLocation + CameraRotation.Vector() * MaxRange;
BulletHit;
FCollisionQueryParams Params(NAME_None, true, OwnerController);
Params.AddIgnoredActor(this);
Params.AddIgnoredActor(GetOwner());
return GetWorld()->LineTraceSingleByChannel(OUT BulletHit, CameraLocation, BulletEnd, ECollisionChannel::ECC_GameTraceChannel1, Params);
}
AController* ARifleBase::GetOwnerController()
{
APawn* OwnerPawn = Cast<APawn>(GetOwner());
if (!OwnerPawn) { return; }
return OwnerPawn->GetController();
}