Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved not close enough to the NavMesh with Instantiated Agents

Discussion in 'Navigation' started by welby, May 14, 2020.

  1. welby

    welby

    Joined:
    Mar 22, 2011
    Posts:
    549
    So I am trying to add a navmesh at runtime. Which I can do and works just fine IF my agent is Already in the scene before running.

    But if I try to instantiate new guys, I get the error:

    "Failed to create agent because it is not close enough to the NavMesh"

    It's the same agent. Same process I use to bake everything else in the scene, which works great for the One agent that already lived there. But no NEW ones will work.




    Thank you so much in advance for any help on this.
    -Welby
     
  2. welby

    welby

    Joined:
    Mar 22, 2011
    Posts:
    549
    Hmmm, ok. Some browsing.

    Suggestions include spawning it higher.
    Or something called Warp.
    And also SamplePosition
    I will give those a go.
     
  3. welby

    welby

    Joined:
    Mar 22, 2011
    Posts:
    549
    ok,..spawning it higher workers.,lol
    Vector3 newPos = new Vector3(pos.x, .5f, pos.z);

    also my prefab had a navmesh on it already, which I removed, since I parent and rebake the NAvMesh Group node containing everythng at runtime anyway.

    cheers
     
  4. agusvila87

    agusvila87

    Joined:
    Mar 2, 2020
    Posts:
    1
    DOUUUUUUU VOCE ES BUERNARDOOOOO <3 THX
     
  5. ChrisKurhan

    ChrisKurhan

    Joined:
    Dec 28, 2015
    Posts:
    266
    In general this can be avoided by doing the following:
    1. Have your NavMeshAgent component disabled on your Prefab
    2. When spawning your enemy, use NavMesh.SamplePosition to find a SpawnLocation
    3. Use NavMeshAgent.Warp(SpawnLocation) before enabling the NavMeshAgent component
    4. Enable your NavMeshAgent component
    In AI Series Part 4 I show how to spawn and place enemies on a NavMesh where you do not encounter this warning.
     
    PepperPaige likes this.