NavmeshAgent SetPath doesn't seem to work?

I’m using CalculatePath to generate an initial path, then modifying the corners of the passed in NavmeshPath object, then I call SetPath on the NavmeshAgent with my modified path. I generated some debug sphere on the corners to make sure I’m getting my expected points, and I am, but after setting the new path, the agent isn’t using it. Is there some other way I should be modifying the path?

My code is below. The idea is to fix the cut corners of the calculated path.

        NavMeshPath path = new NavMeshPath();
        agent.SetDestination(target.position);
        agent.CalculatePath(target.position, path);
       
        for (int i = 0; i < path.corners.Length; i++)
        {
            RaycastHit hitInfo;
            if(Physics.Raycast(path.corners[i] + Vector3.up * 3, Vector3.down, out hitInfo, 10, layerMask))
            {
                Mesh m = hitInfo.collider.gameObject.GetComponent<MeshFilter>().mesh;
                Vector3 center = Vector3.zero;
                for (int j = 0; j < m.vertexCount; j++)
                {
                    center += m.vertices[j];
                }
                center /= ((float)m.vertexCount);
                center = hitInfo.collider.gameObject.transform.TransformPoint(center);

                if (Physics.Raycast(center + Vector3.up * 3, Vector3.down, out hitInfo, 10, layerMask))
                {
                    path.corners[i] = hitInfo.point;
                }

                GameObject tmp = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                tmp.transform.position = path.corners[i];
            }
        }
        agent.SetPath(path);

Ended up saving my modified path separately and pathing to each node manually. I don’t see any reason for the corners get modified by the API since I can path to any arbitrary point when there are only 2 points in the path. It’s only when there are more than 2 that the API seems to muck with what you told it to do.

I am having the exact same issue. I guess I will try either nudging the agent in the direction of the “correct” waypoint or making a custom agent.