Search Unity

There is no 'NavMeshAgent' attached to the ...

Discussion in 'Navigation' started by blvckcat98, Sep 24, 2020.

  1. blvckcat98

    blvckcat98

    Joined:
    Sep 24, 2020
    Posts:
    1
    i have a problem with NavMeshAgent :


    There is no 'NavMeshAgent' attached to the "EnemyPlayer" game object, but a script is trying to access it.
    You probably need to add a NavMeshAgent to the game object "EnemyPlayer". Or your script needs to check if the component is attached before using it.

    my script :




    how can i fix this :(
     

    Attached Files:

  2. deeboss

    deeboss

    Joined:
    Sep 12, 2018
    Posts:
    3
    i also have the same issues it says nav mesh is not attached but a script is trying to access it
     
  3. JungaBoon

    JungaBoon

    Joined:
    Aug 4, 2020
    Posts:
    18
    "Agent = GetComponent<NavMeshAgent>()" is trying to access a navmeshagent that it thinks is attached to the EnemyPlayer.

    GetComponent without anything in front of it defaults to whatever object the script is attached to.
     
  4. Chiron_3003

    Chiron_3003

    Joined:
    Jun 12, 2020
    Posts:
    1
    You have to add the component. This thing all the way down in the Inspector Tab when you clicked on the object where this script is active. Clcik on "Get Component" and search for "Nav Mesh Agent".
     
  5. kirubahars

    kirubahars

    Joined:
    Feb 20, 2023
    Posts:
    1
    Same problem for fps game There is no 'NavMeshAgent' attached to the "ShootingEnemy" game object, but a script is trying to access it.