Player state Casting fails on event begin play?

Hello friends,

I am trying to get the variable from player state in my multiplayer game at the event begin play but casting fails,
And if I try that casting on key event press that time I am able to access the value from player state. I don’t know what the hell is happening in this case.
Please help me.

Just curious: What does the GameMode look like, can you post screenshots of it? and do you have HubZero_PlayerState set in your GameMode as shown below?


Also is the GameMode where you have PlayerState set currently active in the level you are testing this BP out in?

The cast will fail if the PlayerState you are getting does not match the PlayerState you have set in the GameMode properties.

Also is your GameMode in C++ or Blueprints?

Hi friend,
This is how it looks

My game mode is in BP And the same game mode is active in my level in which I am testing.

Judging by that screenshot: Are you still on 4.6?

Get Player Pawn > Get Player State > Cast

You could also add a delay

Try a delay loop and see if that changes the outcome; I’m just curious. See my post

Yes I am using 4.6

I had same problem and the delay did fix it.

Hello ,

I wanted to add that you may want to use Get Controller inside of your character blueprint so that you can get the controller that is currently being used by that specific client.


Make it a great day

The suggestions to use a delay or put the logic into Tick give me the heebie jeebies as a programmer. Instead, my solution for solving the issue where PlayerState was null/unavailable until a few frames after BeginPlay was to put my logic in an overridden version of ACharacter::OnRep_PlayerState(). This gets called as soon as the PlayerState is first assigned, or ever changes.

1 Like

This answer is the cleanest, but will require C++ since ACharacter::OnRep_PlayerState() is not exposed to blueprint.

This one is definietly the best solution. Setting a delay or anything similar is not deterministic. This should be marked as the best answer.

Instead of putting unnecessary stress on the Tick event, or calling Delay without knowing the exact amount of time needed, you can use lazy loading.
If you don’t need that value at instant, just create a GetValue function which checks if the variable has a value. If not, it gets the required data and sets the variable, then just return it.

The best solution would be if Unreal had events triggering when all the required classes are set and ready on the long term.