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"

Player Controller null after RestartPlayer()

I have a simple multiplayer game. When my player dies, the server calls a Player::Die() function which includes this code:

 DetachFromControllerPendingDestroy();
 Destroy();

Later my GameMode iterates through the player controllers and sees that he is dead ( It->Get()->GetPawn() is null) and calls RestartPlayer(PlayerController).

After restarting the player, the APawn::Controller value is null in the player's BeginPlay().

When the player first spawns (before dying) this value is not null in BeginPlay(). But after he dies and the GameMode restarts him, the Controller value is null in his BeginPlay().

Is there any reason why this would happen?

Product Version: UE 4.18
Tags:
more ▼

asked Feb 16 '18 at 08:28 PM in C++ Programming

avatar image

jr557
43 10 9 19

avatar image jr557 Feb 18 '18 at 04:10 PM

After doing some logging it looks like this is happening for my respawn logic:

 SERVER calls DetatchFromControllerPendingDestroy() on client actor
 SERVER calls Destroy() on client actor
 
 SERVER UnPossess
 SERVER Actor Destroyed
 CLIENT UnPossess
 CLIENT Actor Destroyed
 SERVER BeginPlay (NULL controller)
 SERVER Possess Actor

So Possess() gets called after BeginPlay() on the Server and that's why the controller is null in BeginPlay(). But neither Possess() or BeginPlay() get called on the Client.

I have logic that depends on having a valid controller:

 Controller->IsLocalPlayerController();

Where should I put the logic that depends on having a valid Controller after respawning?

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

1 answer: sort voted first

Found the answer I was looking for.. you need to override virtual function:

 APawn::PawnClientRestart()

This is where you would want to do something like attach weapon to first person mesh after respawning.

more ▼

answered Feb 19 '18 at 02:09 AM

avatar image

jr557
43 10 9 19

avatar image LonnyKee Dec 19 '18 at 07:31 PM

Lifesaver - TYSM

(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