StrategyGame and the GetSpectatorPawn() method

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);
    	}
    }

Insted of concentrating on strategy demo, look up APlayerController reference because it part of it’s code

SpectaorPawn is part UE4 default spawn system, it’s 2nd layer used to spawn pawn for player spectating state and keep it in 2nd varable. you can enter it by calling ChangeState(NAME_Spectating); in player controller, it will destroy default pawn and spawn default spectator pawn which you set in SpectatorClass in AGameMode.

But at the end it really does not matter, the camera can be normal pawn it will act the same and operate the same, you will need different possession system for RTS anyway… atleast i think? there might be some code optimizing speculation aspecially in replication.