- Home /
NavMeshAgent.destination vs SetDestination ()
What is the difference? I find there is a lack of detailed information on NavMesh. At the moment, I am using .destination to set an agents destination. I'm also setting this every frame which I presume is bad because I think it calculates a path every time it is set. So should I only be setting its destination once?
Answer by castor · Jul 08, 2016 at 08:56 PM
From what I understood, the main difference is in what both return. The major one being, if you set a destination to an invalid position (e.g. not in the Navmesh) you can handle the case with SetDestination(), but not with NavMeshAgent.destination.
If it's not possible to find a valid nearby navmesh position (e.g. scene has no navmesh) no path is requested. Use SetDestination and check return value if you need to handle this case explicitly.
Answer by xortrox · May 06, 2014 at 02:57 PM
As found by googling NavMeshAgent:
Telling by the documentation, when SetDestination is used it does pretty much the same, however reading the SetDestination documentation:
Note that the path may not become available until after a few frames later. While the path is being computed, pathPending will be true. If a valid path becomes available then the agent will resume movement.
So simply dont set the destination if NavMeshAgent.pathPending is true I guess?
I've read the documentation but it just isn't clear enough. Surely both .destination and SetDestination will have to calculate a path? It doesn't make sense that one would and one wouldn't.
It seems they both do, you can check this by altering destination and then checking if pathPending is true, then once pathPending is no longer true try SetDestination and then check if pathPenging is true, if it's true both times then you will know they both do the same.
Either way, you definitely don't want to keep setting the destination in the Update() loop. Just set it once, and then only set it again if the destination changes.
so based on that? is it better to have AI chase a playerObject with SetDestination() because it will also be changing? .destination is better for static objects?