Set Float based on GetDisanceTo

Hi guys,

I’m trying to change a player’s variable based on their proximity to a world actor/s.

Actor BP: ‘EnergySource’
PlayerState variable: ‘SourceDistance’ (Float)

Below is the logic I have setup in my PlayerController class but when I launch the game, the ‘Print Text’ fires correctly but the variable doesn’t change, it simply prints the same value over and over again. It seems to be an incorrect reference to the player perhaps? I wasn’t sure how to reference a specific world actor so I did it by Array of actors, but I’m not sure if that’s a good way of doing it?


Any direction would be much appreciated :slight_smile:

Thanks - Chap

You shouldnt use GetAllActorsOfClass in the Tick Event, its pretty performance heavy and doing it every frame can be troublesome.

So instead of using the PlayerState as your Target input in the GetDistanceTo node, you will want to use the PlayerCharacter instead. Your PlayerCharacter is the visual representation within the GameWorld, PlayerState itself exists as a data only class and shouldn’t be used for any type of location acquisition as you have attempted there.

Ah yes! of course! I completely over looked that. Thanks very much mate!

Out of interest, how would you suggest I execute the event as apposed to an event tick?

Thanks again!