Search Unity

Multiple NavMeshSurfaces, each with their own set of NavMeshModifierVolumes for a given AgentTypeId

Discussion in 'Navigation' started by Abbrew, Oct 9, 2019.

  1. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417
    Is this possible? My use-case is a peculiar one: I need to be able to generate a cost grid based on every pending soldier's unique tactical situation. Said cost grid is represented by a set of NavMeshModifierVolumes placed around the soldier, and the tactical situation is different for each soldier at any point in time. To implement this behavior I created an Object Pool of around 20 NavMeshSurfaces each sharing the same NavMeshData. In addition another Object Pool of around 500 NavMeshModifierVolumes is used to populate a cost grid using the least number of NavMeshModifierVolumes possible.

    When a soldier wants to find a path, he acquires a NavMeshSurface, waiting for one if one is not currently available. The soldier and the NavMeshSurface are then set to the same, unique AgentTypeId (one of 0-20) He then calculates the cost at each point in a grid, and the minimum number needed of NavMeshModifierVolumes are fetched, resized to populate the grid, and set to the AgentTypeId of the soldier. Finally, an asynchronous job calculates the path.

    I know this is probably not the best use of Unity's Navigation system, so if you can suggest a better way, please let me know. Thank you!