Trouble with PlayerState Being Null

	APlayerItemCache* Cache = GetWorld()->SpawnActor<APlayerItemCache>(MyActorClass, GetActorLocation(),  GetActorRotation());
	PlayerItemCache = Cache;
	PlayerItemCache->SettingsMaxSize = 50;
	if (CurrentPlayerState != NULL)
	{
		CurrentPlayerState->SetPlayerName("Josh");
		UE_LOG(LogTemp, Warning, TEXT("%f"), *CurrentPlayerState->GetPlayerName());	
	} else
	{
		UE_LOG(LogTemp, Warning, TEXT("PlayerState is Null!"));
	}

The PlayerState is null (I currently have this code under BeginPlay), but where would I add it? Currently lost on when exactly player state is not null and read that sometimes it becomes null.

I’m pretty sure CurrentPlayerState is a custom variable you’ve made.
If you’re trying to get a player’s state, you can use the GetPlayerState() function on any pawn.

Though, the player state won’t be of much use to you in this situation since as long as the player itself isn’t null, it’s state won’t be null.

Try adding a delay of a couple of seconds before you try to access the Player State. I’ve found that things sometimes need some time to be created/synchronized (if you’re making a multiplayer game).

I fixed with setting the default player state to the custom one I made then setting CurrentPlayerState then casting my custom class to GetPlayerState()

Adding a small delay fixed my player state null, thank you!

In multiplayer PlayerState might not be initialized in begin play, so PlayerController has “BeginPlayingState”: ‘Pawn has been possessed, so changing state to NAME_Playing. Start it walking and begin playing with it.’

If you access those params in BeginPlayingState instead of BeginPlay, it won’t be null.