# UE4 : GetPlayerState() doesn't work in PlayerController code (template version is called)

**URL:** <https://forums.unrealengine.com/t/ue4-getplayerstate-doesnt-work-in-playercontroller-code-template-version-is-called/509192>\
**Category:** C++\
**Tags:** unreal-engine, UE4, question, CPP\
**Created:** [March 23, 2022, 3:13pm UTC](https://forums.unrealengine.com/t/ue4-getplayerstate-doesnt-work-in-playercontroller-code-template-version-is-called/509192 "2022-03-23T15:13:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hashnut](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@hashnut](https://forums.unrealengine.com/u/hashnut)\
**Post date:** [March 23, 2022, 3:13pm UTC](https://forums.unrealengine.com/t/ue4-getplayerstate-doesnt-work-in-playercontroller-code-template-version-is-called/509192/1 "2022-03-23T15:13:10Z")

</div>

I’m trying to get PlayerState from APawn class, which worked fine in my MyCharacter.cpp code.  
But It doesn’t work, in MyPlayerController.cpp file, which is super weird to me.

My code goes like this :

```auto
auto MyPlayerState = Cast<AMyPlayerState>(GetPlayerState());

```

And GetPlayerState() above is well defined in APawn.h, like this :

```auto
/** If Pawn is possessed by a player, returns its Player State. Needed for network play as controllers are not replicated to clients. */
APlayerState* GetPlayerState() const { return PlayerState; }

```

But whenever I tried to execute the same code in MyPlayerController.cpp, it cannot find matching overload function, instead it gets me this :

```auto
/** Templated convenience version of GetPlayerState. */
template<class T>
T* GetPlayerState() const { return Cast<T>(PlayerState); }

```

Why on earth it tries to call template version of GetPlayerState() in MyPlayerController.cpp, while it works just fine in MyCharacter.cpp file?

Is there any other way to enforce GetPlayerState() not to use template version of GetPlayerState()?

I tried to fix my code to `GetPawn()->PlayerState()`, but this time, unreal engine crashes when game is played…

---

<div class="post-metadata">

**Author:** ![Mallowina](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mallowina](https://forums.unrealengine.com/u/Mallowina)\
**Post date:** [August 18, 2022, 7:26am UTC](https://forums.unrealengine.com/t/ue4-getplayerstate-doesnt-work-in-playercontroller-code-template-version-is-called/509192/2 "2022-08-18T07:26:52Z")

</div>

Just use #include “GameFramework/PlayerState.h”  
And than GetPlayerState() will work normal.

Correct include is important. I was in same situation.  
P.S.: Sorry for my English. I hope than can help you
