Search Unity

SetDestination takes 2 frames unnecessarily

Discussion in 'Navigation' started by Glabrezu, Aug 7, 2015.

  1. Glabrezu

    Glabrezu

    Joined:
    Aug 30, 2014
    Posts:
    24
    I've ran into a problem using NavMeshAgent.SetDestination.

    I set a destination for a cube. It's a really simple path on a simple plane, but the cube only starts moving 2 frames later. Because of pathfinding, you'll say. But it's not the case.
    Later in the update, but in the same frame after setting the destination, I check if the path is being calculated, and it says yes: pathPending is true.
    Then in the NEXT frame I check if the path is still being calculated, and it's not: pathPending is already false in the next frame, but the movement still hasn't started.
    Then in the next frame after that one, the movement starts.

    It's too much time for me. So after I set the destination, in the same frame I call CalculatePath. Then, still in the same frame, I check if the path is already complete or at least partial. I take the coordinates of Path.corners[1] and teleport my cube slightly towards that corner (the exact distance it would've crossed in 2 frames if it was moving correctly).

    This is a very weird workaround and I'm not comfortable with it, because I end up calculating the path twice. Is there no way to make the Agent move immediately? 2 frames is too much, and there's no reason for it to wait that long, especially when it can already move in the next frame.

    Is it a bug?
     
  2. Glabrezu

    Glabrezu

    Joined:
    Aug 30, 2014
    Posts:
    24
    I've disabled VSync and it solved the issue. The cube now moves as soon as it has calculated its path.
     
    TEBZ_22 likes this.