Search Unity

100,000 entities traversing navmesh

Discussion in 'Entity Component System' started by zulfajuniadi, Jun 4, 2018.

  1. Radu392

    Radu392

    Joined:
    Jan 6, 2016
    Posts:
    210
    How are the paths computed in the OP video? I see that the 'Awaiting Path' field is bigger than 0 only when spawning new entities, meaning that existing paths never get refreshed once computed? If so, then the performance is not all that great.

    Since it looks like it's using cached paths, does that mean it doesn't support runtime manipulation of the nav graph (adding/removing obstacles)?
     
    Last edited: Nov 3, 2019
  2. Djayp

    Djayp

    Joined:
    Feb 16, 2015
    Posts:
    114
    https://github.com/zulfajuniadi/unity-ecs-navmesh/blob/master/Assets/Demo/Scripts/Behaviours/
    In the sample you can add new buildings using the BuildingCacheSystem. The DetectIdleAgentSystem will enqueue idle agents and assign them a destination from the "Commercial" buildings in the BuildingCacheSystem (see Building.cs and DemoSystems.cs).

    https://github.com/zulfajuniadi/unity-ecs-navmesh/tree/master/Assets/NavJob/Systems
    The NavAgentSystem will then request a path to the NavMeshQuerySystem. If the path is cached the NavMeshQuerySystem invokes the success callbacks, else it enqueues a PathQueryData. OnUpdate, it uses NavMeshQuery on 256 jobs slots (see NavAgentSystem.cs and NavMeshQuerySystem.cs).
    Existing paths don't get refreshed but I don't understand why performances wouldn't be great with cached paths. You can use PurgeCache() if you need to empty it. It's using NavMeshModifier component to add/remove obstacles, so it already involves baking a NavMesh at runtime (see https://github.com/zulfajuniadi/uni...Assets/Demo/Scripts/Behaviours/TownBuilder.cs).
    Code (CSharp):
    1. GetComponent<BuildNavMesh> ().Build ((AsyncOperation operation) =>
    2. {
    3.     NavMeshQuerySystem.PurgeCacheStatic ();
    4.     Debug.Log ("Town built. Cache purged.");
    5. });
     
    Radu392 likes this.
  3. Gaaammmler

    Gaaammmler

    Joined:
    Apr 10, 2018
    Posts:
    16
    Hey Guys,

    i'm PodeCaradox from Github, i changed the Systems to work with the new Entites Package but i don't saw the avoidance system updated. If i use the old one i changed a little bit it does weird things, maybe you will update the Github?



    I saw in the old one you don't use the avoidance variable:
    Code (CSharp):
    1.  
    2. public void ExecuteNext(int firstIndex, int index)
    3.             {
    4.                 var agent = agents[entities[index]];
    5.                 var avoidance = avoidances[entities[index]];
    6.                 var move = Vector3.left;
    7.                 if (index % 2 == 1)
    8.                 {
    9.                     move = Vector3.right;
    10.                 }
    11.                 float3 drift = agent.rotation * (Vector3.forward + move) * agent.currentMoveSpeed * dt;
    12.                 if (agent.nextWaypointIndex != agent.totalWaypoints)
    13.                 {
    14.                     var offsetWaypoint = agent.currentWaypoint + drift;
    15.                     var waypointInfo = navMeshQuery.MapLocation(offsetWaypoint, Vector3.one * 3f, 0, agent.areaMask);
    16.                     if (navMeshQuery.IsValid(waypointInfo))
    17.                     {
    18.                         agent.currentWaypoint = waypointInfo.position;
    19.                     }
    20.                 }
    21.                 agent.currentMoveSpeed = Mathf.Max(agent.currentMoveSpeed / 2f, 0.5f);
    22.                 var positionInfo = navMeshQuery.MapLocation(agent.position + drift, Vector3.one * 3f, 0, agent.areaMask);
    23.                 if (navMeshQuery.IsValid(positionInfo))
    24.                 {
    25.                     agent.nextPosition = positionInfo.position;
    26.                 }
    27.                 else
    28.                 {
    29.                     agent.nextPosition = agent.position;
    30.                 }
    31.                 agents[entities[index]] = agent;
    32.             }
    33.         }

    A Update would be pretty nice, and thanks for the git it helped me alot. :)

    Also maybe for the Raycasts, the new Physics System would be nice :)
     
    Last edited: Nov 6, 2019
  4. Banksy

    Banksy

    Joined:
    Mar 31, 2013
    Posts:
    376
    an interesting thread... just wanted to say I'm following along.
     
  5. LudiKha

    LudiKha

    Joined:
    Feb 15, 2014
    Posts:
    140
    Anybody here managed to update this project to the Entities 0.4.0 version?
     
    Opeth001 likes this.