# Pawn PlayerState reference on client is sometimes NULL

**URL:** <https://forums.unrealengine.com/t/pawn-playerstate-reference-on-client-is-sometimes-null/325481>\
**Category:** Character & Animation\
**Tags:** playerstate, client, unreal-engine, bug-report, question\
**Created:** [July 16, 2015, 11:39am UTC](https://forums.unrealengine.com/t/pawn-playerstate-reference-on-client-is-sometimes-null/325481 "2015-07-16T11:39:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_1d9d25db](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1d9d25db](https://forums.unrealengine.com/u/anonymous_user_1d9d25db)\
**Post date:** [July 16, 2015, 11:39am UTC](https://forums.unrealengine.com/t/pawn-playerstate-reference-on-client-is-sometimes-null/325481/1 "2015-07-16T11:39:10Z")

</div>

I have run into some problems with PlayerState reference inside Pawn class. PlayerState is sometimes NULL on clients. This happens right after loading up a level with a server and multiple clients. It is still NULL if you keep waiting for many minutes, so it should not be a replication issue. It is also completely random which clients it happens with and on how many.

I have provided an image where I show that PlayerState reference is NULL on two of clients.

 ![50432-image1.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/1/5/915107f266ae84c8b7221b9c2cf2ff9c9ce9c7c2.jpeg)

I have managed to isolate this issue down to Player Controller function BeginSpectatingState that is called immediately at startup on all clients (I dont know why this function is called). way I see it, following is what normally happens:

- When level has loaded up and gameplay has started, server calls Possess and PossessedBy for clients. At this point, PlayerState reference for Pawns are set to point to same as Controller PlayerState. PlayerState is eventually replicated down to client. (I have tested that this replication successfully happens).
- Sometimes however, BeginSpectatingState function is called after this replication happen. problem is that this function calls UnPossessed for Pawn which again sets PlayerState to NULL on client.
- Since this sometimes happens after PlayerState was replicated from server, I believe this may be what causes it to be NULL.

This issue only happens sometimes, and only on clients. Most of time, PlayerState is ok. I have managed to reproduce this issue in a project based on Third Person template. Please see my explanation below for modifications I made:

**Reproducable steps:**

Using Engine version 4.8.2, I created a project based on C++ Third Person template, and did following modifications:

- Create a C++ function in custom character class with below code. Also make sure to add input to project that calls this function when clicking left mouse button (or any other button). We will just use this function to check if PlayerState is NULL.

To test, click Play button as Standalone Game from inside editor and test with at least four players (1 listen server and 3 clients). (Testing with more than two players increases chances for it to happen). I also used following settings: Uncheck “Use Single Process” and use Editor Multiplayer Mode as “Play As Listen Server”.

When clicking left mouse button on some of clients, you will hopefully see that on some of them, PlayerState reference is reported as being NULL. Most of time however, PlayerState reference is ok, therefore it is a good idea to test multiple times. Hopefully you will see it as NULL some of times.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_33800a51](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_33800a51](https://forums.unrealengine.com/u/anonymous_user_33800a51)\
**Post date:** [July 16, 2015, 4:16pm UTC](https://forums.unrealengine.com/t/pawn-playerstate-reference-on-client-is-sometimes-null/325481/2 "2015-07-16T16:16:38Z")

</div>

Hi ,

I’ve assigned a member of our team to look into this issue for you, and they’ll post here if they require any additional information. Thanks for your report!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [July 16, 2015, 8:28pm UTC](https://forums.unrealengine.com/t/pawn-playerstate-reference-on-client-is-sometimes-null/325481/3 "2015-07-16T20:28:09Z")

</div>

Hey -

I tried testing this by calling function on LMB click. With 4 players I only saw PlayerState as NULL once however Controller-\>PlayerState was NULL as well. After next frame when I clicked again they were both “ok”. This only occurred once out of about 15 tried with four players each time. all other attempts showed all players as ok when I clicked. How often are you seeing PlayerState as NULL with Controller-\>PlayerState being ok and is there anything else that might increase odds of this occurring?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_1d9d25db](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1d9d25db](https://forums.unrealengine.com/u/anonymous_user_1d9d25db)\
**Post date:** [July 16, 2015, 9:54pm UTC](https://forums.unrealengine.com/t/pawn-playerstate-reference-on-client-is-sometimes-null/325481/4 "2015-07-16T21:54:40Z")

</div>

Hello

For me, at least every third or fourth time that I test this, PlayerState is NULL on at least one of clients. Controller-\>PlayerState is always ok.

It is also important to note that for me, when PlayerState is reported as NULL, it stays permanently NULL. Even if I have game instance running for several minutes, PlayerState is still NULL when I click LMB.

At moment I dont know about anything else that might increase odds for this occurring.

As I said in my original post I also believe this problem occurs because BeginSpectatingState function is called for Controller on clients at startup. This function will sometimes call UnPossess which effectively sets PlayerState to NULL on local clients. I have also tested that, for any of these clients, servers authorative version of this PlayerState is ok.

I am going to sleep now since I live in norway, but when I wake up tomorrow, I will try to create a project where this happens for me and post it here so that maybe you can take a look at same project as me. Maybe this will help. I will also see if I can find out anything more about this problem.

Thank you very much for taking a look at this.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_1d9d25db](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1d9d25db](https://forums.unrealengine.com/u/anonymous_user_1d9d25db)\
**Post date:** [July 17, 2015, 11:31am UTC](https://forums.unrealengine.com/t/pawn-playerstate-reference-on-client-is-sometimes-null/325481/5 "2015-07-17T11:31:04Z")

</div>

I have created a new project now in engine version 4.8.2, and overriden several functions and added debug messages to screen inside them to see when and if they are called. I have included project as an attachment. You will have to rebuild project after unzipping file. following modifications are done (in C++):

- **Inside BugTestProjectCharacter class, I have done following:**
- Added function checkPlayerState. This function is called when clicking LMB.
- I have overriden UnPossessed function declared in Pawn.
- **I then added a new class called BugTestProjectPlayerController that extends from PlayerController. Inside this class, I have done following:**
- I have overriden BeginSpectatingState function declared in PlayerController.
- I have overriden UnPossess function declared in Controller.
- **Finally, I modified BugTestProjectGameMode to use BugTestProjectPlayerController class as its Player Controller.**

**To test project, make sure to do following:**  
Click Play in editor as “Standalone Game” with following settings under Advanced Settings → Multiplayer Options:

- Number of players: 4
- Uncheck “Use Single Process”
- Editor Multiplayer Mode: “Play as Listen Server”

link text

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_1d9d25db](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1d9d25db](https://forums.unrealengine.com/u/anonymous_user_1d9d25db)\
**Post date:** [July 17, 2015, 11:42am UTC](https://forums.unrealengine.com/t/pawn-playerstate-reference-on-client-is-sometimes-null/325481/6 "2015-07-17T11:42:02Z")

</div>

I have tested project multiple times now with four players and can report following findings:

- Sometimes, PlayerState is ok on all clients.
- Most of time, PlayerState is NULL on either one client or two of clients.
- PlayerState can also be NULL on all three clients (Occurs very rarely).

I also believe I know why PlayerState is sometimes NULL. At start of game, server will initialize everything, among PlayerState for all clients. PlayerState will eventually be replicated down to client. Also at startup, BeginSpectatingState function is called on all clients. If GetPawn() is not NULL, this function calls UnPossess which again calls GetPawn()-\>UnPossessed. This function sets PlayerState to NULL on client. If this call happens after PlayerState was replicated down to client, I believe client now sets its own PlayerState reference to NULL, which is why PlayerState is NULL on some of clients.

**This is screen output I get:**

**When PlayerState is NULL** , I get following screen output:

- ABugTestProjectCharacter::UnPossessed
- ABugTestProjectPlayerController::UnPossess
- GetPawn() != NULL
- ABugTestProjectPlayerController::BeginSpectatingState
- GetPawn() == NULL
- ABugTestProjectPlayerController::BeginSpectatingState

**When PlayerState is ok** , I get either this screen output:

- GetPawn() == NULL
- ABugTestProjectPlayerController::BeginSpectatingState

or this screen output (Same as first one):

- ABugTestProjectCharacter::UnPossessed
- ABugTestProjectPlayerController::UnPossess
- GetPawn() != NULL
- ABugTestProjectPlayerController::BeginSpectatingState
- GetPawn() == NULL
- ABugTestProjectPlayerController::BeginSpectatingState

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [July 23, 2015, 2:10pm UTC](https://forums.unrealengine.com/t/pawn-playerstate-reference-on-client-is-sometimes-null/325481/7 "2015-07-23T14:10:07Z")

</div>

Hey Gardennnnnnn-

We were able to find repro for this issue and have submitted a bug report (UE-19058) for investigation.

Cheers

---

<div class="post-metadata">

**Author:** ![Wrekk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Wrekk](https://forums.unrealengine.com/u/Wrekk)\
**Post date:** [November 26, 2015, 2:12pm UTC](https://forums.unrealengine.com/t/pawn-playerstate-reference-on-client-is-sometimes-null/325481/8 "2015-11-26T14:12:19Z")

</div>

I still have this issue, is it fixed?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [November 27, 2015, 12:51pm UTC](https://forums.unrealengine.com/t/pawn-playerstate-reference-on-client-is-sometimes-null/325481/9 "2015-11-27T12:51:17Z")

</div>

Hey -

I checked status of ticket I had entered, and it is still open. Unfortunately we do not have any estimate for when it will be resolved. However, I have added a comment to ticket to indicate this is still affecting people.

Cheers

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_76ae4db4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_76ae4db4](https://forums.unrealengine.com/u/anonymous_user_76ae4db4)\
**Post date:** [December 10, 2015, 12:02am UTC](https://forums.unrealengine.com/t/pawn-playerstate-reference-on-client-is-sometimes-null/325481/10 "2015-12-10T00:02:18Z")

</div>

Thanks , just FYI we’re seeing this exact same issue on our project Space Dust Racers as well, both in 4.8 and 4.10 (after upgrading).

And thanks for filing detailed bug report !

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_76ae4db4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_76ae4db4](https://forums.unrealengine.com/u/anonymous_user_76ae4db4)\
**Post date:** [February 13, 2016, 3:44am UTC](https://forums.unrealengine.com/t/pawn-playerstate-reference-on-client-is-sometimes-null/325481/11 "2016-02-13T03:44:27Z")

</div>

Hi , has there been any progress on UE-19058? We’re still seeing it in UE4.10. It’d be great if we could fix it before release!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [February 16, 2016, 5:14pm UTC](https://forums.unrealengine.com/t/pawn-playerstate-reference-on-client-is-sometimes-null/325481/12 "2016-02-16T17:14:19Z")

</div>

Hey sds–

UE-19058 has not been resolved yet. If there is any information specific to your case that has not been mentioned here I can add it to report.

Cheers

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_76ae4db4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_76ae4db4](https://forums.unrealengine.com/u/anonymous_user_76ae4db4)\
**Post date:** [February 16, 2016, 11:46pm UTC](https://forums.unrealengine.com/t/pawn-playerstate-reference-on-client-is-sometimes-null/325481/13 "2016-02-16T23:46:04Z")

</div>

Thanks . We’re seeing it in Development and Shipping builds somewhat infrequently (perhaps 1/100?) when a client joins a server (this happens in separate processes, not a single process through editor). I’ve tried testing with different lag simulation settings but it doesn’t seem to make a huge difference. Cheers!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_ce19271c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ce19271c](https://forums.unrealengine.com/u/anonymous_user_ce19271c)\
**Post date:** [February 18, 2016, 3:02am UTC](https://forums.unrealengine.com/t/pawn-playerstate-reference-on-client-is-sometimes-null/325481/14 "2016-02-18T03:02:32Z")

</div>

(this is unfortunately not an answer but system would not let me post my bug confirmation with more than 2000 characters otherwise)

Hi everyone

We experienced some random editor crashes when testing our multiplayer game with more than 1 player in PIE where `PlayerState` on a clients locally controlled pawn suddenly was `NULL` even though it was successfully received in `OnRep_PlayerState` before.

Turns out that in some cases `PlayerState` on the `APawn` can get replicated before `SpectatorClass` in `AGameState` gets replicated. In that case, `AGameState` then calls `ReceivedSpectatorClass` which then goes on to put all local player controllers into spectator mode. Controllers entering spectator mode will UnPossess pawn and that in turn sets `PlayerState` back to `NULL`.

I have made a tiny test project which implements a custom AGameMode, AGameState and APawn which just logs out when relevant steps are called during initialization. Then during bad late call to AMyPawn::UnPossessed and during AMyPawn::Tick it prints a message that things are going badly.

It is seems very much a race condition in that it happens very randomly. Sometimes it doesn’t happen at all between editor starts and sometimes it happens every second time. Sometimes it happens more often when testing with 4 or more PIE players instead of just 2.

Here is me running project in PIE 4 times with 2 players. First and fourth time ended up with client pawn having no PlayerState. I set log output to just print info from client (HasAuthority() == false) and only included lines regarding controlled pawn here.

* * *

```
[0.00] AMyGameMode::OnConstruction
[0.00] AMyGameMode::RestartPlayer
[0.28] AMyGameMode::RestartPlayer
[0.34] AMyPawn OnConstruction - PlayerState: 0x0 - State: Has No Controller
[0.37] AMyPawn OnRep_PlayerState - PlayerState: 0x4674e400 - State: Spectating
[0.37] AMyGameState OnConstruction
[0.37] AMyGameState ReceivedSpectatorClass
[0.37] AMyPawn UnPossessed - PlayerState: 0x4674e400 - State: Spectating
[0.37] AMyPawn UnPossessed due to ReceivedSpectatorClass during init after receiving PlayerState will remove PlayerState again
[0.37] AMyPawn BeginPlay - PlayerState: 0x0 - State: Has No Controller
[0.37] AMyGameState BeginPlay
[0.59] AMyPawn Restart - PlayerState: 0x0 - State: Spectating
[0.60] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[0.72] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[0.84] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[0.96] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[1.08] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[1.20] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[1.33] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[1.45] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[1.57] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[1.69] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[1.82] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[1.94] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[2.06] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[2.19] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[2.31] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[2.43] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[2.56] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[2.68] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[2.81] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[2.94] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[3.07] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[3.07] AMyPawn EndPlay - PlayerState: 0x0 - State: Playing
[3.07] AMyPawn UnPossessed - PlayerState: 0x0 - State: Playing
[3.07] AMyGameState EndPlay
[3.07] AMyGameMode::EndPlay

```

* * *

```
[0.00] AMyGameMode::OnConstruction
[0.00] AMyGameMode::RestartPlayer
[0.24] AMyGameMode::RestartPlayer
[0.27] AMyPawn OnConstruction - PlayerState: 0x0 - State: Has No Controller
[0.29] AMyGameState OnConstruction
[0.29] AMyGameState ReceivedSpectatorClass
[0.29] AMyPawn UnPossessed - PlayerState: 0x0 - State: Spectating
[0.29] AMyPawn BeginPlay - PlayerState: 0x0 - State: Has No Controller
[0.29] AMyGameState BeginPlay
[0.33] AMyPawn OnRep_PlayerState - PlayerState: 0x427c4800 - State: Has No Controller
[0.53] AMyPawn Restart - PlayerState: 0x427c4800 - State: Spectating
[1.12] AMyPawn EndPlay - PlayerState: 0x427c4800 - State: Playing
[1.12] AMyPawn UnPossessed - PlayerState: 0x427c4800 - State: Playing
[1.12] AMyGameState EndPlay
[1.13] AMyGameMode::EndPlay

```

* * *

```
[0.00] AMyGameMode::OnConstruction
[0.00] AMyGameMode::RestartPlayer
[0.23] AMyGameMode::RestartPlayer
[0.28] AMyPawn OnConstruction - PlayerState: 0x0 - State: Has No Controller
[0.30] AMyGameState OnConstruction
[0.30] AMyGameState ReceivedSpectatorClass
[0.30] AMyPawn UnPossessed - PlayerState: 0x0 - State: Spectating
[0.30] AMyPawn BeginPlay - PlayerState: 0x0 - State: Has No Controller
[0.30] AMyGameState BeginPlay
[0.33] AMyPawn OnRep_PlayerState - PlayerState: 0x59365600 - State: Has No Controller
[0.53] AMyPawn Restart - PlayerState: 0x59365600 - State: Spectating
[0.96] AMyPawn EndPlay - PlayerState: 0x59365600 - State: Playing
[0.96] AMyPawn UnPossessed - PlayerState: 0x59365600 - State: Playing
[0.96] AMyGameState EndPlay
[0.96] AMyGameMode::EndPlay

```

* * *

```
[0.00] AMyGameMode::OnConstruction
[0.00] AMyGameMode::RestartPlayer
[0.27] AMyGameMode::RestartPlayer
[0.32] AMyPawn OnConstruction - PlayerState: 0x0 - State: Has No Controller
[0.34] AMyPawn OnRep_PlayerState - PlayerState: 0x33dc9600 - State: Spectating
[0.34] AMyGameState OnConstruction
[0.34] AMyGameState ReceivedSpectatorClass
[0.34] AMyPawn UnPossessed - PlayerState: 0x33dc9600 - State: Spectating
[0.34] AMyPawn UnPossessed due to ReceivedSpectatorClass during init after receiving PlayerState will remove PlayerState again
[0.34] AMyPawn BeginPlay - PlayerState: 0x0 - State: Has No Controller
[0.34] AMyGameState BeginPlay
[0.57] AMyPawn Restart - PlayerState: 0x0 - State: Spectating
[0.58] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[0.70] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[0.82] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[0.94] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[1.06] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[1.18] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[1.31] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[1.43] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[1.55] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[1.68] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[1.80] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[1.92] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[2.04] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[2.17] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[2.29] AMyPawn Tick on bad pawn! - PlayerState: 0x0 - State: Playing
[2.29] AMyPawn EndPlay - PlayerState: 0x0 - State: Playing
[2.29] AMyPawn UnPossessed - PlayerState: 0x0 - State: Playing
[2.29] AMyGameState EndPlay
[2.30] AMyGameMode::EndPlay

```

* * *

As one can see on bad first and fourth attempt, `AMyPawn` gets constructed and then gets `OnRep_PlayerState` right away even before `AMyGameState` gets constructed (all happening seemingly on same tick, same time stamp). On second and third correct run `ReceivedSpectatorClass` happens what seems a tick before `OnRep_PlayerState`.

We confirmed this on two machines with 4.10.2, 4.10.3 and 4.11.0 preview 5.

test project is attached.

Thanks for looking into this,

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [February 18, 2016, 3:20pm UTC](https://forums.unrealengine.com/t/pawn-playerstate-reference-on-client-is-sometimes-null/325481/15 "2016-02-18T15:20:06Z")

</div>

Hey -

Thank you for detailed information about pawn/playerstate/game state. I have updated bug report to include this information as well as sample project you provided.

Cheers

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_76ae4db4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_76ae4db4](https://forums.unrealengine.com/u/anonymous_user_76ae4db4)\
**Post date:** [February 19, 2016, 5:12am UTC](https://forums.unrealengine.com/t/pawn-playerstate-reference-on-client-is-sometimes-null/325481/16 "2016-02-19T05:12:29Z")

</div>

This might also help, I was able to reproduce this issue much more frequently after a server travel using these network settings:  
-pktloss=2 -pktlag=75 -pktlagvariance=10 -pktdup=2 -pktorder=1

---

<div class="post-metadata">

**Author:** ![Chris.Ranney](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Chris.Ranney](https://forums.unrealengine.com/u/Chris.Ranney)\
**Post date:** [August 1, 2016, 7:05pm UTC](https://forums.unrealengine.com/t/pawn-playerstate-reference-on-client-is-sometimes-null/325481/17 "2016-08-01T19:05:56Z")

</div>

We were seeing this relatively consistently in a test project, and I was able to track down what I believe is reason for some of calls not working as expected.

short version of the “fix” is to test for GetPawn() == nullptr in ReceivedSpectatorClass() before calling BeginSpectatingState(). That way only on initial connect does it cause a problem. In our case, this fixed problem. We also had a second potential fix that involved rebuilding PlayerState pointer inside of client reset when it acknowledged pawn. This however still caused Pawn value to thrash by switching to a spectator pawn and back.

long version of what was happening, based on my testing, was as follows. Note that our Pawn class was loaded via LoadClass and was not loaded by GameMode’s default values.

1. Net Player joins
2. Player pawn class is loaded via GetDefaultPawnClassForController
3. Player pawn is spawned via SpawnDefaultPawnFor
4. ClientRestart() is called inside of Server’s Possess
5. ClientRestart() sends a null for NewPawn since PackageMap has not ack’d pawn class (blueprint class)
6. ClientRestart() happens on client, sets to NULL pawn, does not enter Playing state since Pawn is null
7. Controller’s Pawn replicates, calls OnRep\_Pawn, sets Pawn
8. Pawn’s PlayerState replicates, calls OnRep\_PlayerState, sets PlayerState
9. GameState’s SpectatingClass replicates, calls OnRep\_SpectatorClass, which calls ReceivedSpectatorClass, which is forwarded to all local player controllers
10. Since state is Spectating because ClientRestart() failed, and SpectatingPawn is null, it calls BeginSpectatingState()
11. BeginSpectatingState() sees that Pawn variable is set, calls Unpossess()
12. Unpossess clears Pawn’s PlayerState variable on client
13. ClientRestart() is called again on a retry with correct Pawn value.
14. ClientRestart() uses SetPawn rather than possess, which does NOT set PlayerState locally
15. ClientRestart() AcknowledgesPawn
16. ClientRestart() changes state to Playing

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_fe6006f1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_fe6006f1](https://forums.unrealengine.com/u/anonymous_user_fe6006f1)\
**Post date:** [September 12, 2016, 8:13pm UTC](https://forums.unrealengine.com/t/pawn-playerstate-reference-on-client-is-sometimes-null/325481/18 "2016-09-12T20:13:49Z")

</div>

This issue still seems to be occurring in 4.12.5 and is a real issue for my current project. I’m working on a workaround involving re-launching clients with invalid network setups automatically but this is just trying to work around issue. This issue was originally posted over a year ago, has no progress been made on it in all that time?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [September 12, 2016, 8:20pm UTC](https://forums.unrealengine.com/t/pawn-playerstate-reference-on-client-is-sometimes-null/325481/19 "2016-09-12T20:20:19Z")

</div>

Hey bdavey-

This issue was tested and has not been seen to occur as of 4.13. Please try making a copy of your project and let me know if you still have this occurring on your end in latest engine version.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f282f3af](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f282f3af](https://forums.unrealengine.com/u/anonymous_user_f282f3af)\
**Post date:** [May 2, 2018, 9:56am UTC](https://forums.unrealengine.com/t/pawn-playerstate-reference-on-client-is-sometimes-null/325481/20 "2018-05-02T09:56:12Z")

</div>

I am still experiencing this issue in 4.19, building off of 1st Person template.

[Next page](https://forums.unrealengine.com/t/pawn-playerstate-reference-on-client-is-sometimes-null/325481.md?page=2)
