LocalNavMeshBuilder - how to build for different agent types

Hi,
I am using the LocalNavMeshBuilder to make the Navmesh in real time, working fine expect for any agents that use a different agent type, such as the default of Orge instead of human can’t use the navmesh?

error:
Failed to create agent because it is not close enough to the NavMesh
UnityEngine.Object:Instantiate(Enemy, Vector3, Quaternion)
SpawnerEnemies:SpawnEnemyTypes(EnemyType) (at Assets/Scripts/SpawnerEnemies.cs:94)
SpawnerEnemies:SpawnWave() (at Assets/Scripts/SpawnerEnemies.cs:74)
SpawnerEnemies:Update() (at Assets/Scripts/SpawnerEnemies.cs:56)
SetDestination" can only be called on an active agent that has been placed on a NavMesh.
UnityEngine.AI.NavMeshAgent:SetDestination(Vector3)
c__Iterator0:MoveNext() (at Assets/Scripts/Enemy.cs:84)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
Enemy:Start() (at Assets/Scripts/Enemy.cs:50)

You need to have two LocalNavMeshBuilders in this instance, one for each agent type. For instance in the Github example scene #4, duplicate the LocalNavMeshBuilder and the Agent. Set the second agent type as ogre and have the second LocalNavmeshBuilder target that agent. Bam. It’s important to realize that having an extra agent type means double the navMeshes.

Hi,
thanks for replying, but that doesn’t resolve the issue.
LocalNavMeshBuilder target is a transform, you can’t make it target an agent type.

1 Like

Having the same issue. In Unity 2020.1.4f1 with NavMeshComponents 2020.1.

Did you (or anyone else) find a solution to this.

I tried modifying the LocalNavMeshBuilder script to operate on an array of NavMesh data instead of a single one, but have so far only succeeded in crashing the Unity editor.

Ciao, nella dichiarazione della classe LocalNavMeshBuilder aggiungi un campo agente come segue :

    [SerializeField ]
     NavMeshAgent agente;

Nella void UpdateNavMesh cambial la var defaultBuildSettings come segue :

var defaultBuildSettings = NavMesh.GetSettingsByID(agente.agentTypeID);

Sulla scena duplica il LocalNavMeshBuilder object e seleziona il tipo agente per ogni istanza.

Probabilmente si può migliorare la soluzione ma al momento a me così ha funzionato.

Ciao


Hi, in the LocalNavMeshBuilder class declaration add an agent field as follows:

 [SerializeField]
      NavMeshAgent agente; [/ code]

In the void UpdateNavMesh change the defaultBuildSettings var as follows:
[code = CSharp]
var defaultBuildSettings = NavMesh.GetSettingsByID (agente.agentTypeID); [/ code]

On the scene duplicate the LocalNavMeshBuilder object and select the agent type for each instance.

You can probably improve the solution but at the moment it worked for me.

Hello

To perhaps improve on @Gestionesito79 here’s how I implemented this…

[SerializeField]
private int agentTypeInt;
//Modify UpdateNaveMesh
//var defaultBuildSettings = NavMesh.GetSettingsByID(0);
var defaultBuildSettings = NavMesh.GetSettingsByID(agentTypeInt);

Now you can simply set the Navmesh Agent type ID number to target the various Agents types rather then having to assign an actual navmesh agent gameobject