"Get Distance To" not updating

If I move an actor then use “Get Distance To”, it appears to use the original position rather than the new position of the actor.

What do you mean by “move an actor” ?

Do you mean using one of the SetActorLocation / AddActorLocalOffset / AddActorWorldOffset … or adding InputVector to its MovementComponent?

Movement component apply its input to its owner later in the tick updates so if you’re moving using MovementComponent it won’t change the result of GetDistanceTo in the current frame.

I am using SetActorLocation. Is there any way I can use Get Distance To so that the new movement component is applied?

SetActorLocation should work, can you please give us more information about your script and actors ?

I’m not 100% sure but i think the “Target Self” in the GetDistanceTo within GetClosestTile is pointing to your Controller and not your Character.

To check, put an input in you function for you player reference and plug that in.

In my Player Controller, I have this

39543-controller.png

. Get Closest Tile is this function

. Multiple instances of the tiles are spawned when the game starts, covering the floor, and are used for movement locations. When the pawn is moved, Get Closest Tile still returns the tile that was closest at the start.

To move the player, I have this in the Tile class.

I forgot 1 very simple question: what’s the default value of NearestDistance variable ? (if it’s 0 you will never find a better tile than the default one :p)

Default is 10000. I’ll try that when I get home, thanks!

Tried this, same result.

I found the problem, I wasn’t resetting the value of my NearestDistance variable.