I have to cast everytime I want a reference to player or the player state?

Trying to save the player state as a reference variable so I can use it later.

It is set from spawn at beginplay and a print/test confirms it saves the player state correctly.

Literally beginplay > cast from controller > get state and save as ref

If I use the cast everytime it works properly but if I attempt to use the one that is saved it will return accessed none everytime. Is there a reason I can’t save my player state? It feels stupid that I have to cast when the state isn’t changed.

Any help appreciated, thanc

Edit: Bump, still no answer and can’t find any info on the web. This seems to not just be a player stat problem as well. If I want any reference to the player or state I have to cast every. Single. Time.

Which just feels very inefficient for storing info to the state. Is there a reason I can’t just set a reference and forget about it?

Two things: delay or proper class

With construction like this (delay can help :wink:

You need still cast to proper class that you defined at ‘world settings’. (Here I have own PlayerController_J class)

I don’t touch ‘Player State’ so I can use it right from node.

UE4.26

Generating HUD at beginning of game takes time. So if you don’t have a little delay you got ‘empty’ object. Try it :slight_smile:

I don’t understand how does a delay do anything here? And that’s basically what I’m doing, I just use casts to set the references as I have custom controller, player, state and hud.

Hmm no dice, even with a delay. I think it’s because I’m using a custom player state, when I use get player state it is the default one, not mine. And for some reason saving a reference to it also won’t work.

Yes this is exactly what I do. But if I try to use the reference later it will always return accessed none.

On Event BeginPlay in whatever actor you want to access the player state do Event BeginPlay->get player controller->get player controller-> cast to your playerstate → then drag off your player state and promote to variable

1 Like