Player prefab with NavMesh agent not working

I have a navmesh in game and I want my player spawnet using NewtworkManager to be controlled using NavMesh agent.

I have followed following:

  • Added a new game object to the scene and rename it to “NetworkManager”.
  • Added the NetworkManager component to the new game object.
  • Added the NetworkManagerHUD component to the game object.
  • Created the Player prefab. The player prefab has a navmesh agent attached.
  • Added Networkidentity component to player prefab.
  • Added NetworkTransform to player prefab.
  • Check the LocalPlayerAuthority box on the NetworkIdentity.
  • Set the playerPrefab in the “Spawn Info” section on the NetworkManager to the player prefab
  • 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

Did you find a work around ? i have been facing the same problem .

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)

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.

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.

3 Likes

Thank you! This worked with prefab NavMeshAgents pulled out of a pool.

1 Like

Thank you!! This is going very well