# Player state Casting fails on event begin play?

**URL:** <https://forums.unrealengine.com/t/player-state-casting-fails-on-event-begin-play/309120>\
**Category:** Character & Animation\
**Tags:** playerstate, casting, unreal-engine, question\
**Created:** [March 4, 2015, 11:13am UTC](https://forums.unrealengine.com/t/player-state-casting-fails-on-event-begin-play/309120 "2015-03-04T11:13:01Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ganesh\_Mune\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ganesh\_Mune\_1](https://forums.unrealengine.com/u/Ganesh_Mune_1)\
**Post date:** [March 4, 2015, 11:13am UTC](https://forums.unrealengine.com/t/player-state-casting-fails-on-event-begin-play/309120/1 "2015-03-04T11:13:01Z")

</div>

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.

 ![32182-capture1.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/4/d/b4d63a04f6642e2b8f69a0834427f9014692adc1.jpeg)

---

<div class="post-metadata">

**Author:** ![cchulo.dev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@cchulo.dev](https://forums.unrealengine.com/u/cchulo.dev)\
**Post date:** [March 4, 2015, 11:24am UTC](https://forums.unrealengine.com/t/player-state-casting-fails-on-event-begin-play/309120/2 "2015-03-04T11:24:28Z")

</div>

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?

![32180-capture.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/8/3/c8367e1924b7fd312e03a49a00d26e88a683f1ac.png)

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?

---

<div class="post-metadata">

**Author:** ![Ganesh\_Mune\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ganesh\_Mune\_1](https://forums.unrealengine.com/u/Ganesh_Mune_1)\
**Post date:** [March 4, 2015, 1:09pm UTC](https://forums.unrealengine.com/t/player-state-casting-fails-on-event-begin-play/309120/3 "2015-03-04T13:09:31Z")

</div>

Hi friend,  
This is how it looks

 ![32186-capture2.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/7/f/27f2b2d93c641ae7902f4d28854b085a4e61b840.jpeg)

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

---

<div class="post-metadata">

**Author:** ![cchulo.dev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@cchulo.dev](https://forums.unrealengine.com/u/cchulo.dev)\
**Post date:** [March 5, 2015, 12:46am UTC](https://forums.unrealengine.com/t/player-state-casting-fails-on-event-begin-play/309120/4 "2015-03-05T00:46:56Z")

</div>

Judging by that screenshot: Are you still on 4.6?

---

<div class="post-metadata">

**Author:** ![DG\_Gage](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DG\_Gage](https://forums.unrealengine.com/u/DG_Gage)\
**Post date:** [March 5, 2015, 2:07am UTC](https://forums.unrealengine.com/t/player-state-casting-fails-on-event-begin-play/309120/5 "2015-03-05T02:07:36Z")

</div>

Get Player Pawn \> Get Player State \> Cast

You could also add a delay

---

<div class="post-metadata">

**Author:** ![Purecyn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Purecyn](https://forums.unrealengine.com/u/Purecyn)\
**Post date:** [March 5, 2015, 3:15am UTC](https://forums.unrealengine.com/t/player-state-casting-fails-on-event-begin-play/309120/6 "2015-03-05T03:15:21Z")

</div>

Try a delay loop and see if that changes the outcome; I’m just curious. See my post [https://answers.unrealengine.com/questions/183488/player-controller-get-controlled-pawn-client-delay.html](https://answers.unrealengine.com/questions/183488/player-controller-get-controlled-pawn-client-delay.html)

---

<div class="post-metadata">

**Author:** ![Ganesh\_Mune\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ganesh\_Mune\_1](https://forums.unrealengine.com/u/Ganesh_Mune_1)\
**Post date:** [March 9, 2015, 6:29am UTC](https://forums.unrealengine.com/t/player-state-casting-fails-on-event-begin-play/309120/7 "2015-03-09T06:29:41Z")

</div>

Yes I am using 4.6

---

<div class="post-metadata">

**Author:** ![Inph1del](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/inph1del/32/1148459_2.png) [@Inph1del](https://forums.unrealengine.com/u/Inph1del)\
**Post date:** [April 24, 2016, 11:16am UTC](https://forums.unrealengine.com/t/player-state-casting-fails-on-event-begin-play/309120/8 "2016-04-24T11:16:38Z")

</div>

I had same problem and the delay did fix it.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_e729f54e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e729f54e](https://forums.unrealengine.com/u/anonymous_user_e729f54e)\
**Post date:** [September 28, 2016, 8:36pm UTC](https://forums.unrealengine.com/t/player-state-casting-fails-on-event-begin-play/309120/9 "2016-09-28T20:36:57Z")

</div>

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.

Example:

 ![108833-casttoplayerstatehelp.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/6/5/865c9cccb95acff7dbf34418c02a331b97498fc5.png)

Make it a great day

---

<div class="post-metadata">

**Author:** ![jm991](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@jm991](https://forums.unrealengine.com/u/jm991)\
**Post date:** [March 16, 2019, 3:58pm UTC](https://forums.unrealengine.com/t/player-state-casting-fails-on-event-begin-play/309120/10 "2019-03-16T15:58:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![PaulTacos](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PaulTacos](https://forums.unrealengine.com/u/PaulTacos)\
**Post date:** [November 13, 2019, 11:49am UTC](https://forums.unrealengine.com/t/player-state-casting-fails-on-event-begin-play/309120/11 "2019-11-13T11:49:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2fedf584](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2fedf584](https://forums.unrealengine.com/u/anonymous_user_2fedf584)\
**Post date:** [June 14, 2020, 9:15pm UTC](https://forums.unrealengine.com/t/player-state-casting-fails-on-event-begin-play/309120/12 "2020-06-14T21:15:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bpetrovicz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@bpetrovicz](https://forums.unrealengine.com/u/bpetrovicz)\
**Post date:** [February 16, 2021, 8:00pm UTC](https://forums.unrealengine.com/t/player-state-casting-fails-on-event-begin-play/309120/13 "2021-02-16T20:00:59Z")

</div>

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.
