x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How can I get GetSpectatorPawn() to work?

Hello.

I have a problem with GetSpectatorPawn(). I've created a camera like in Strategy Game Sample, but it doesn't work as expected. I belived it's caused by the problem in movement component's TickComponent() function. I obtain player pawn like in Strategy Game Sample:

 ATowerDefensePlayerController* PlayerController = Cast<ATowerDefensePlayerController>(PawnOwner->GetController());
 AWaveDefensePlayerPawn* PlayerPawn = Cast<AWaveDefensePlayerPawn>(PlayerController->GetSpectatorPawn());

But PlayerPawn is always NULL (Propably because PlayerController->GetSpectatorPawn() returns NULL). How to make it work? :D

Product Version: Not Selected
Tags:
more ▼

asked Apr 29 '14 at 06:42 PM in C++ Programming

avatar image

Ogniok
150 11 13 16

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

I had the same issue, but this forum thread cleared it up for me.

The reason GetPawn() works and GetSpectatorPawn() works is because they are dependent on the state of the PlayerController: Playing, Spectating, Inactive. Look at the comment for GetSpectatorPawn():

/** Get the Pawn used when spectating. NULL when not spectating. */

So in this case, you are currently in the "playing" state, but the pawn classes happen to be the same for both playing and spectating in your case.

By default the PC starts in the spectator state but immediately changes to playing at the start of the game. If you want to always spectate you can force it by setting it on the PlayerState using bOnlySpectator. Look at the APlayerController::Reset() function to see how that is handled (changes the bIsPlayerWaiting flag, which allows spectators to transition to playing).

This stuff probably warrants some cleanup on our end, but for now hopefully this gets you moving forward!

In short, you can fix the problem by overriding the Reset function:

 void AMyPlayerController::Reset()
 {
     Super::Reset();
 
     PlayerState->bOnlySpectator = true;
 }

I'm still not clear on how this works in the strategy game sample, since it doesn't do this, but this fix worked for me.

more ▼

answered Mar 13 '17 at 01:13 AM

avatar image

mlindgren
1 1

(comments are locked)
10|2000 characters needed characters left

Just to clarify Strategy Game Sample. It works without putting player in Playing state, because they have AStrategyGameMode::RestartPlayer override, which doesn't call Super::RestartPlayer, and in turn AGameModeBase::RestartPlayer calls AGameModeBase::RestartPlayerAtPlayerStart and there is a logic which spawns default pawn, which happens if you don't override RestartPlayer or do call Super::RestartPlayer, but doesn't happend in StrategyGameMode.

I think it's rather inconsistant example, because their PlayerState is always in bIsSpectator = false, while controller runs around rampaging with spectatorpawn :-).

more ▼

answered Nov 19 '18 at 11:10 AM

avatar image

dldls
22 4 9

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question