Search Unity

Issue with multiple NavMeshDataInstances interference. Two runtime locally built navmeshes.

Discussion in 'Navigation' started by tapawafo, Feb 13, 2018.

  1. tapawafo

    tapawafo

    Joined:
    Jul 25, 2016
    Posts:
    170
    I'm using the local navmesh builder, one spawned for each agent, at that agent's position, and tracking that agent. In order to ensure the agent gets assigned a navmesh, I delay agent activation until after the localNavmeshBuilder is spawned and active.

    I found that when I spawned multiple agents in the same area, one of the agents would be 'bound' or assigned to the others navmesh. It seems to always be the 2nd spawned enemy that is tied to the 1st spawned local navmesh.

    At first I thought this was because their spawns sometimes overlapped, so when the agents assigned themselves to the nearest navmesh, the same one was chosen. To work around this, I start each localNavMeshBuilder's size to be very small so they would never overlap. After a few seconds' delay, the size is increased to normal size.

    However, even with that workaround, it seems that, after agent B walks into agent A's navmesh instance, and tries to walk out, it still gets stuck on the edge of NavMesh A. Despite its own navmesh, the one it started on and was presumably assigned to, expanding beyond that point (since it's centered/tracked on agent B.)

    Here's an illustration, mind the crappy drawing skill:




    I guess what I'm after is a way to assign a navMeshAgent to a specific navMeshDataInstance? However I can't find a way to do this through the docs. I can't use one large LocalNavMeshBuilder navmesh because of the game's scene size + distance between spawned enemies.


    Thanks for any help.


    EDIT:
    (See below comment)

    After moving the target around a bit more it was able to move past the edge. Still a strange issue however. It definitely gets stuck at the other navmesh's edge. Maybe until it auto repaths?
     
    Last edited: Feb 17, 2018
  2. tapawafo

    tapawafo

    Joined:
    Jul 25, 2016
    Posts:
    170
    Update:

    Can confirm the above seems to be untrue or at the very least inconsistent. Here's an image showing the issue better:



    The agent spawns far away. Its own localNavMeshBuilder navmesh can be seen roughly centered on it.

    A second navmeshbuilder navmesh, stationary at origin, can be seen on the left (relative to the agent's mesh.) When the agent enters this mesh, it then gets stuck trying to leave that mesh. Even though it initially spawned and registered/claimed ownership/whatever to its own navmesh.


    I'd be seriously grateful for any help with this problem.

    Thanks for reading.
     
  3. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,212
    There is nothing visible to show what navmesh they are linked to or anyway to find what navmeshes are in the area etc... I'm considering all kinds of hacky approaches =[

    In the meantime I've gotten my agents to move to different navmeshes with a simple coroutine:

    Code (CSharp):
    1.     IEnumerator Push () {
    2.         agent.enabled = false;
    3.         NavMeshHit hit;
    4.         if (NavMesh.SamplePosition(Vector3.MoveTowards(agent.transform.position, target.position, 0.2f), out hit, 5f, NavMesh.AllAreas)) {
    5.             agent.transform.position = hit.position;
    6.         }
    7.         yield return null;
    8.         agent.enabled = true;
    9.         agent.SetDestination(target.position);
    10.     }
    you want to make sure you're not throwing them off of any navmesh or it will throw an error when you try to call agent.SetDestination() though that might work if you give it another frame to place itself. Detecting when an agent is stuck and in need of this is the hard part.
     
    tapawafo likes this.
  4. tapawafo

    tapawafo

    Joined:
    Jul 25, 2016
    Posts:
    170
    I haven't either - really frustrating. :( It's pretty crazy to me that nobody but us two seems to have run into this; I'd thought this would be a common enough scenario to have two overlapping navmeshes. I might try posting in some other threads to see if someone might have some more info.

    Thanks so much for the coroutine, I'll give it a shot. :)
     
  5. tapawafo

    tapawafo

    Joined:
    Jul 25, 2016
    Posts:
    170
    I'm having a lot of difficulty finding a simple way to identify when the issue is occurring with my AI system and so I was wondering about other approaches.

    @malkere Do you think it would be naive or perhaps not performant to try and rework the LocalNavMeshBuilder to create only one NavMeshDataInstance and rebuild that using the combined bounds/collected data of all of the individual tracked agents? (Two scripts, the single LocalNavMeshBuilder and a set of scripts for each tracked Agent that creates and sends the necessary local data to the main script for combining and building.)

    I'm not sure if this will work for a variety of reasons, but I can't help but think the performance might not be hit too badly since the same amount of NavMesh building would be occurring, that is unless 1 large mesh has much worse performance than several smaller meshes.

    I'm cautiously optimistic as the LocalNavMeshBuilder really doesn't use that much in resources even with several agents with quite large (200x150x200) bounds in my testing.
     
  6. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,212
    I've quite seriously considered that... trying to fall asleep in bed... I never did test it... I turn off AI past 200m (400x400) and I already force a OnNavMesh check before turning AI on in OnEnable, so if there was a 400x400 mesh following the player around it might work with no borders... but in my case, players place buildings and facilities and things that the navmesh needs to be updated with so ultimately having small chunks, I'm running 105x105 right now and it's almost realtime and working well. Otherwise there would be an almost constant thread running in the background just for navmesh.

    I've also thought about making each quadrant a different ID and updating agents IDs when the move across a border threshold to pin them to the proper NavMesh, but it's working well enough for now....

    Maybe for defense missions I will draw a single 400x400 NavMesh as they are pinned at a specific location for the duration, but ultimately the system is still just really lacking in capability despite quite a few months now =[
     
    tapawafo likes this.
  7. theyareseven

    theyareseven

    Joined:
    Aug 20, 2017
    Posts:
    5
    I am currently running into this issue, I have multiple 'AI' that use the local navmesh builder (on each 'AI') and when far apart, they walk around fine but when spawned close together (Meshes overlap) the system gets confused, while it knows the 'target' and position to goto it seems to auto complete right away and not move the 'agent' until one mesh agent moves away dropping the overlaps ect, did you two get anywhere with this matter?
     
  8. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,212
    If you are giving them each their own navmesh you should be able to assign each mesh a unique agent ID and assign 1 agent per mesh. Haven't tried that kind of work specifically though.
     
  9. theyareseven

    theyareseven

    Joined:
    Aug 20, 2017
    Posts:
    5
    I suspect I can do something about that, but your forum is def a big help, running into crazy problems with navmeshing lol
     
    malkere likes this.