Reference to controller?

Hey I am new too unreal so it might be a noob question.

At the moment I have this. It gets my character controller which has the character health.

I don’t like that I have to call this every tick so is there a way of getting a reference too the controller and just keep it.
(Or perhaps via a pointer?)
Don’t want to do a cast everytime my UI changes either that’s why I am trying to cache the controller.

Thanks already!

Hey there, on event construct do a get owning player and save it as a variable (cast it to your custom player controller if needed), on the tick you just use that variable.

Hi,

There is a GetPlayerController node already for you that you can access from any blueprint! Right click anywhere in your blueprint and search for Get Player Controller. You should see the node and other similar nodes appearing :slight_smile:

However, you might still need to cast it to your own custom controller. You can do this for every one of those Tick Event! just cast once for Event Begin Play and save it into a variable. Alternatively, if you’re sure that your cast will never fail, then right click on the cast node and select “convert to pure cast” and you will no longer need an execution node for it.

Hope this helps :slight_smile:

for some reason it wasn’t working when I got my character from my GameMode. Even tough I have it in there as a variable.
Could that be that the GameMode BeginPlay event is called later then the UI construct event.