With the the old OffMeshLink and NavMeshAgent you could get the GameObject the current OffMeshLink was attatched to by doing…

However with the new NavMeshLink, this doesn’t work. agent.isOnOffMeshLink still works fine but the link.offMeshLink returns as null. Anyone have an idea what to do?
2 Likes
if(agent.isOnOffMeshLink)
{
OffMeshLinkData data = agent.currentOffMeshLinkData;
if(data.offMeshLink)
{
Debug.Log("on OFFmeshLink: " + data.offMeshLink.name, data.offMeshLink.gameObject);
}
else
{
Object owner = agent.navMeshOwner;
Debug.Log("on NAVmeshLink: " + owner.name, (owner as Component).gameObject);
}
}
The built in NavMeshLink sets itself as owner on the agent when it is being traversed, so thats how you would get information about it. You can cast the owner object to a component (or NavMeshLink specifically) to get access to the gameobject it is attached to.
10 Likes