Search Unity

Player prefab with NavMesh agent not working

Discussion in 'Connected Games' started by rishi-ranjan, Oct 31, 2015.

  1. rishi-ranjan

    rishi-ranjan

    Joined:
    Oct 7, 2015
    Posts:
    22
    I have a navmesh in game and I want my player spawnet using NewtworkManager to be controlled using NavMesh agent.

    I have followed following:

    1. Added a new game object to the scene and rename it to “NetworkManager”.
    2. Added the NetworkManager component to the new game object.
    3. Added the NetworkManagerHUD component to the game object.
    4. Created the Player prefab. The player prefab has a navmesh agent attached.
    5. Added Networkidentity component to player prefab.
    6. Added NetworkTransform to player prefab.
    7. Check the LocalPlayerAuthority box on the NetworkIdentity.
    8. Set the playerPrefab in the “Spawn Info” section on the NetworkManager to the player prefab
    9. Remove the player object instance from the scene if it exists in the scene

    After this my NavMesh agent script is being called but if I try to access any variables or fucntion on NavMesh agent, I get an error "
    "can only be called on an active agent that has been placed on a NavMesh."

    I did rebake my NavMesh. How do I make this work?

    Thanks,
    Rishi
     
  2. GamerSuji

    GamerSuji

    Joined:
    Aug 1, 2015
    Posts:
    5
    Did you find a work around ? i have been facing the same problem .
     
  3. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,138
    This is not networking related. But rather has to do with the Navmesh. If you try to spawn a NavMeshAgent at runtime. You have to spawn it close to the Navmesh. (Don't know the exact max distance, But I guess a meter or so)
     
  4. GamerSuji

    GamerSuji

    Joined:
    Aug 1, 2015
    Posts:
    5
    Yea tweaked it, but i am getting "can only be called on an active agent that has been placed on a NavMesh." but before making it a prefab it was working perfect.
     
  5. Viscarious

    Viscarious

    Joined:
    Jul 29, 2017
    Posts:
    1
    I'm not sure if I faced the exact same issues, but I was definitely encountering an issue with NavMesh and SpawnPoints as part of the Network Manager. My solution was to disable the Nav Mesh Agent in the prefab and enable it in the Start function of a script attached to my prefab.
     
    gOscar likes this.
  6. gOscar

    gOscar

    Joined:
    Jun 17, 2018
    Posts:
    2
    Thank you! This worked with prefab NavMeshAgents pulled out of a pool.