CalculatePath agents stuck

Agents are getting stuck running against and not pathing around objects. My navmesh is baked and agents dont have any issue moving around randomly, but once they encounter an object thats in the way of the destination they get stuck. I’m trying to use just CalculatePath without using SetDestination, since its a huge performance issue.

Also looks like there is another issue where ChooseWaypoint() only works the first time and won’t be able to find a new path after that.

    public Vector3 destination;

    public void WanderUpdated()
    {
        float distanceToWanderPosition = Vector3.Distance(transform.position, destination);
        if (distanceToWanderPosition <= 15)
        {
            ChooseWaypoint();
        }
        else
        {
            var step = 50.0f * Time.deltaTime;
            transform.position = Vector3.MoveTowards(transform.position, destination, step);
            Vector3 direction = (destination - transform.position).normalized;
            Quaternion lookRotation = Quaternion.LookRotation(new Vector3(direction.x, 0, direction.z));
            transform.rotation = Quaternion.RotateTowards(transform.rotation, lookRotation, Time.deltaTime * 300.0f);
        }
    }

    void ChooseWaypoint()
    {
        Vector3 randomDirection = Random.insideUnitSphere * 800;
        randomDirection += transform.position;
        NavMeshHit hit;
        NavMesh.SamplePosition(randomDirection, out hit, 800, 1);
        Vector3 finalPosition = hit.position;
        NavMeshPath path = new NavMeshPath();
        if (NavMesh.CalculatePath(transform.position, finalPosition, NavMesh.AllAreas, path))
        {
            destination = finalPosition;
        }
    }

You are only using the final position to move the agent.
You calculate a path and don’t even use it.
You need to use the actual path to avoid obstacles.

Use path.status to check if it is a complete path or not and path.corners to traverse the path and it will avoid obstacles.

SetDestination is only a performance issue if you are running it every frame in update on a lot of agents with a very long path. I’ve had this running with up to 32 agents in update with small distances and performance has never been an issue (though thats not an advisable way to do it)
A simple method would be

Pick a point to move to and use the path.status to see if the path is valid
If it is set the destination once
Now calculate the distance from the agent (who is now moving) to the destination point (in every frame)
If the distance is <= to the navAgent stopping distance then you reached the destination and can repeat the operation.