Getting a player-controlled object to move to another object that is not strictly tied to a navmesh

Basically, what I want to do is whenever a player clicks on a specifically tagged object in a map, the player model uses the navmesh to navigate to that object (like a point-and-click game).

I feel like there is a really easy answer to this that I’m missing, but either way, could someone explain to me how to achieve this exactly? Also, C# would be nice if you provide code.

First you need to check which obect is clicked.

  • Either check every mouse click and do a raycast in direction to the mouse cursor to get the clicked object.
  • Possibly you can do this with checking onmouseenter/leave inside the object but I’m not exactly sure it would work.

After you are certain that the object is clicked, get it’s position on the navmesh and use SetDestination or CalculatePath to make the agnet go there.