C++ PlayerState Cast Fails but BP doesnt


Am i casting Wrong

You can also call the templated version of the GetPlayerState() function. (Although that shouldn’t make a difference)

AShooterPlayerState* MyPlayerState = GetPlayerState<AShooterPlayerState>();

When exactly do you call this? This will only return a playerstate when the pawn from which you call it is possesed.

It is a function in the character that needs to retrieve a value from playerstate

I am casting to the player state to call function on the player state from the character

Is this the wrong way to call functions on player state

It is to call a function on the players playerstate

No it’s a right way to do this, in what function do you call this?

I’m just thinking this might be returning null if you call this in the constructor of your character.
I’d also use nullptr instead of NULL, although that should not be the issue either I think.

( Coding Standard | Unreal Engine Documentation )

That’s what I thought, it probably has to do with where you call it, cause your character may not be possessed yet at the time you call the function.
Can you show more of your code? It’s hard to troubleshoot with minimal information.

This value is specific to each players playerstate

I’ve been testing around and it seems to cast successfuly in possessedBy but not a normal function in the character

It’s a bit hard to show because there are functions getting called from all over the place

although you have just reminded me it could be because the character isn’t possessed at the time of the cast

I say this because it is on a pre die function and the order of things may be wrong

Thank you for staying with me