I'm using 2 navmeshsurface components on one mesh object, each has a different agent type . While calling NavMesh.XXX(Singleton class to access the baked NavMesh) it always gets the first one. How to access another navmesh? Any advice would be appreciated.
Write your own class and assign both NavMeshes to that one. The NavMesh class was never really adapted to work with multiple navmeshes as far as I know.
Thanks! But my problem is that I don't know how to distinguish and hold 2 navmeshs first (through code) so that I could assign them later. I was tring to get [NavMeshHit]s separately on two navmeshsurface component. Otherwise, is there anyway to apply [SamplePosition] on NavMeshSurface? https://docs.unity3d.com/ScriptReference/AI.NavMesh.SamplePosition.html public NavMeshSurface surfacePlayer; public NavMeshSurface surfaceEnemy;
Unfortunately you'd have to solve that by exposing the NavMeshComponents for that new class in the editor, then drag and drop in the corresponding NavMeshes. Not very generation-friendly but there isn't really a way to differentiate, indeed. If I look through the source code it seems like you can't call SamplePosition on an individual Component, unfortunately. What exactly do you want to use the SamplePosition for?
I want to use SamplePosition to return different hit (out AI.NavMeshHit), in order to get NavMeshSurface's height offset individually. Then I can apply this offset to agents' baseOffset.
hmmm, wouldn't it be a lot simpler to just make a trigger area that offsets a NavMeshAgent's base offset when entered and lowers it again on exit?
Worth a try Thanks! Just want to calculate each surface's height offset more accurately.That's the reason why I used SamplePosition.
I get that, but NavMesh Heights aren't always reliable (and heightmeshes apparently aren't implemented for NavMeshSurface Components right now, meaning stairs etc would quickly give wrong results) and they're kindof expensive since they go through the NavMesh Queries which are limited in number per frame. You're probably better off with a method like what I proposed here.
Yeah I got it, I hope NavMeshSurface Components could implement heightmeshes someday. It's really nice of you to discuss this with me ,Thanks and I'll give it a go.