Hi,
In my game i have an agent and multiple different offmesh links.
i would like to move to using unity 5.6 and the new navmeshlinks system but i have a major issue…
i need to have different types of navmesh links eg some to indicate for the agent to jump and some to indicate for the agent to climb a ladder. with offmesh links i did this from the agent by going navmeshagent.currentoffmeshlinkdata.offmeshlink.tag and if the tag of the offmesh link was for instance ladder i could code what i wanted him to do for a ladder. If the tag was smalljump i could code in a parabola for a certain jump ect.
but with navmeshlinks i cannot seem to identify them in any way… i cannot find the tag of the navmeshlink… and navmeshagent.navmeshowner gives me no use-able data from what i can tell… please help. It should be simple i know but i cannot seem access the navmeshlink or navmeshlink gameobject from the agent script.
You prob. have a script on your transfer object anyway. So you could add something like this to your start method of a script that is attacked to your NavMeshLink GameObject
NavMeshLink navMeshLink = GetComponent<NavMeshLink>();
navMeshLink .m_LinkInstance.owner = link;
This will require to change the NavMeshLink class and make m_LinkInstance internal, or write a getter for it.
But this way your LinkInstance has the navMeshLink object as owner and you can access it from the agent like:
if (agent.isOnOffMeshLink){
NavMeshLink link = agent.navMeshOwner as NavMeshLink;
...
}
after checking if your agent hit a NavMeshLink
as Ash-Blue suggested
I have a work around by going navmeshagent.navmeshowner.name and then if the name of the gameobject is for instance ladder i can do my ladder code… But i would much rather use tag then changing the gameobject name
Create a link as normal and assign the owner to any valid Object
. In this case it should be a container that holds your string.
var myObj = new MyObj {myString = "TagAsString"};
var inst = NavMesh.AddLink(myLinkData);
inst.owner = myObj;
Now you can pull out that string through NavMeshAgent.navMeshOwner
when NavMeshAgent.isOnOffMeshLink
returns true.
Object owner = agent.navMeshOwner;
if ((owner as NavMeshLink).area == NavMesh.GetAreaFromName(“Walkable”))
{
// do something…
}