The height of the agent does not sync correctly with the graph

Hi, I am creating custom AiLerp script and have removed Update () procedure, I am updating paths only when I need it and it works quite well the only problem I have is that the height of the agent is not following the height of the grid graph , if I add this procedure:
protected virtual void Update ()
{
if (shouldRecalculatePath) SearchPath ();
}
if it updates the height of the agent to that of the graph but because I have to do this if the route I previously calculated 1 time and I only update it when I need it (when there is an alteration of the map)

for now to solve the problem I modify the position and nexposition:
MovementUpdate (Time.deltaTime, out nextPosition, out nextRotation);
nextPosition.y = Terrain.activeTerrain.SampleHeight (nextPosition);
But this should not be done since it consumes a lot of resources, I await your answer, thanks

Hi

This depends on what modifiers you are using for your agent. The funnel modifier has an option to preserve the height called ‘split at every portal’. The raycast modifier may discard some height information, though.
Normally, the height of the graph is not very accurate anyway, so I wouldn’t recommend that you rely on it significantly for visual effects.

So the only correct way is to use the function mentioned above? (Terrain.activeTerrain.SampleHeight (nextPosition))

Yes, or some other method of getting the height (e.g. a raycast)