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

Spawnning Agents are not working

Discussion in 'Navigation' started by tonOnWu, May 2, 2018.

?

Why agents are not working when they are spawn after surface is cooked

  1. Possible incompatibility with ARKit

    0 vote(s)
    0.0%
  2. A bug on the library

    100.0%
Multiple votes are allowed.
  1. tonOnWu

    tonOnWu

    Joined:
    Jun 23, 2017
    Posts:
    83
    Hi guys.

    I'm working on a project where NPC are spawn randomly in time. The problem I've found is that if I spawn an enemy after the surface has been baked, the NPC doesn't move.

    I tried to bake the surface every time a NPC is spawn, but that creates an extra random movement to the rest of NPC that are already over the surface.

    By the way, my game is developed using ARKit and all playing action is in an area of 2 by 2. That makes the NPC's very small in scale. I don't think that this has relation with the problem but I think is an important extra information.

    Any suggestions are appreciated.
     
  2. newjerseyrunner

    newjerseyrunner

    Joined:
    Jul 20, 2017
    Posts:
    966
    My guess is that your agent is not exactly on the mesh. I solved this issue by in the start method first warping the character up a unit or two, then finding the closest navmesh point to that, and snapping it to it.
     
    tonOnWu likes this.
  3. Deejayfistfang

    Deejayfistfang

    Joined:
    Dec 4, 2017
    Posts:
    8
    My game uses half of its pathfinding by Navmesh, and half just override and making the Enemy react to it's target, ignoring Navmesh constraints. For Example, if the player gets to place where the navmesh isn't baked or it's too small, than your navmesh enemy is broken. But maybe I can help.

    The navmesh agent, when it SPAWNS or when the scene is started in it, will check if it's on or near-enough to a Navmesh to be an active Navmesh Agent. If it is not, it will stop working immediately and is hard to restart. Check your Console for errors. I recommend using Warping like newjerseyrunner said, because it fixes the placement of your navmesh agent to the transform position.
     
    tonOnWu likes this.
  4. tonOnWu

    tonOnWu

    Joined:
    Jun 23, 2017
    Posts:
    83
    Thank you... that was it.
     
    newjerseyrunner likes this.
  5. newjerseyrunner

    newjerseyrunner

    Joined:
    Jul 20, 2017
    Posts:
    966
    Very common mistake. It took me forever to figure that out.