1

I'm having some problems on instantiating an enemy in unity, it gives me always this error setDestination" can only be called on an active agent that has been placed on a NavMesh., and then it places a 2d model somewhere in my map

    public GameObject enemy;
    public Transform spawn;
    // Start is called before the first frame update
    void Start()
    {
        spawnNew();
    }
    void spawnNew() {

        Instantiate(enemy, spawn.transform.position, Quaternion.identity);
        
    }
Jeral
  • 45
  • 4
  • There is nothing wrong with your code that correlates to your error. Please provide a better minimal reproducible example: https://stackoverflow.com/help/minimal-reproducible-example – Tomasz Juszczak Mar 07 '21 at 23:43

1 Answers1

0

After you have spawned an enemy, call the NavMeshAgent.Warp() function to position the agent on the desired position, which of course must be inside the navmesh.