Search Unity

LocalNavMeshBuilder - how to build for different agent types

Discussion in 'Navigation' started by Ardinius, May 14, 2017.

  1. Ardinius

    Ardinius

    Joined:
    Oct 4, 2015
    Posts:
    57
    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)
    <AI>c__Iterator0:MoveNext() (at Assets/Scripts/Enemy.cs:84)
    UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    Enemy:Start() (at Assets/Scripts/Enemy.cs:50)
     
  2. christougher

    christougher

    Joined:
    Mar 6, 2015
    Posts:
    558
    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.
     
  3. Ardinius

    Ardinius

    Joined:
    Oct 4, 2015
    Posts:
    57
    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.
     
    OMOH98 likes this.
  4. kalelovil

    kalelovil

    Joined:
    Jan 2, 2013
    Posts:
    1
    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.
     
  5. Gestionesito79

    Gestionesito79

    Joined:
    Mar 21, 2022
    Posts:
    1
    Ciao, nella dichiarazione della classe LocalNavMeshBuilder aggiungi un campo agente come segue :
    Code (CSharp):
    1.     [SerializeField ]
    2.      NavMeshAgent agente;
    Nella void UpdateNavMesh cambial la var defaultBuildSettings come segue :
    Code (CSharp):
    1.                
    2. 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:
    [code = CSharp] [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
     
  6. christougher

    christougher

    Joined:
    Mar 6, 2015
    Posts:
    558
    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