Hi, I’m trying to understand how works a strategy camera.
With the Strategy Game example I figure out it needs to check the boundaries for the movements of my SpectatorPawn into its SpectatorMovementComponent.
In the tick function of the movement component, before clamping the camera location, checks if the spectator Pawn and its movement component are valid but to retrive the spectator pawn, GetSpectatorPawn() is used instead of GetPawn().
Replicating this on a blank module this doesn’t work, because the spectator pawn got, is always NULL (using GetPawn() works).
This is a problem already asked for:
here and here.
I’m trying to figure out why on strategy game it works.
I also tried to set the the player state on spectating only, like suggested in the above topics, but it doens’t work too.
Still I’m interested why GetSpecatorPawn() is used instead of GetPawn() and why doesn’t work in my project (and how to fix using GetSpectatorPawn()).
Thanks.
void USKSpectatorPawnMovement::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction * ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
if (!PawnOwner || !UpdatedComponent)
{
return;
}
ASKPlayerController* PlayerController = Cast<ASKPlayerController>(PawnOwner->GetController());
if (PlayerController && PlayerController->IsLocalController())
{
if (!bInitialLocationSet)
{
PawnOwner->SetActorRotation(PlayerController->GetControlRotation());
PawnOwner->SetActorLocation(PlayerController->GetSpawnLocation());
bInitialLocationSet = true;
}
FVector MyLocation = UpdatedComponent->GetComponentLocation();
ASKSpectatorPawn* SpectatorPawn = Cast<ASKSpectatorPawn>(PlayerController->GetSKSpectatorPawn());
//check(SpectatorPawn); //always crash
if ((SpectatorPawn != NULL) && (SpectatorPawn->GetSKCameraComponent() != NULL))
{
SpectatorPawn->GetSKCameraComponent()->ClampCameraLocation(PlayerController, MyLocation);
}
UpdatedComponent->SetWorldLocation(MyLocation, false);
}
}