# How can I set the remaining distance of the nav agent?

I have an issue with the nav agent in my game. That I am using the remaining distance to determine the next state of the AI.

When the navagent is first given a destination it uses the previous distance until it is next updated.

So my plan is to find the memory of the remaining distance and alter it when I set the destination. Is that possible or is there a better way?

• So the problem is that you do something like agent.destination = x; but the remaining distance updates only on the next frame? Would it be a problem if you waiting one frame? Instead of finding the memory of remaining distance (which is both impossible and a not very good idea) couldn't you just use another variable that has this "altered value" and use that until remaining distance updates? – TomTsagk Sep 28 '18 at 11:58
• @TomTsagk I could but that seems less elegant than forcing it to update the distance. – PStag Sep 28 '18 at 15:47
• When you say something like "find the memory of the remaining distance and alter it" this hints that you can calculate the remaining distance yourself, in which case, why do you want to wait for the variable to update? Unfortunately Unity is very generous in giving away frames when it comes with NavMesh and NavMeshAgent, so unless you write something manually, there's no other alternative. – TomTsagk Sep 28 '18 at 15:53