Search Unity

Mirror Multiplayer and Nav

Discussion in 'Navigation' started by anthonyrandomcarey, Feb 28, 2022.

  1. anthonyrandomcarey

    anthonyrandomcarey

    Joined:
    Feb 27, 2022
    Posts:
    1
    Hello everyone! I'm pretty new so I am gonna try to break this down the best I can.
    I followed Mirror's quick start guide for multiplayer and it works great. The problem I am having is with the playerscript, where I am using baked in navigation on the floor and a nav mesh agent on the player.

    When I play the game and start the server as host, I can click around and move fine. When I open up another instance of Unity and connect as the client I get the "Failed to create agent because there is no valid NavMesh" warning and then when I click to move I get the ""SetDestination" can only be called on an active agent that has been placed on a NavMesh" error.

    Here is my playerscript.cs:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using Mirror;
    4. using UnityEngine;
    5. using UnityEngine.AI;
    6.  
    7. namespace QuickStart
    8. {
    9.     public class PlayerScript : NetworkBehaviour
    10.     {
    11.  
    12.         NavMeshAgent agent;
    13.  
    14.         void Start()
    15.         {
    16.             agent = GetComponent<NavMeshAgent> ();
    17.         }
    18.  
    19.         void Update()
    20.         {
    21.             if (!isLocalPlayer) { return; }
    22.  
    23.             if(Input.GetMouseButtonDown(0))
    24.             {
    25.                 RaycastHit hit;
    26.                 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    27.                 if(Physics.Raycast(ray, out hit, Mathf.Infinity));
    28.                 {
    29.                     agent.SetDestination(hit.point);
    30.                 }
    31.             }
    32.         }
    33.     }
    34. }
     
    oscarverhagen501 likes this.
  2. oscarverhagen501

    oscarverhagen501

    Joined:
    Dec 12, 2021
    Posts:
    1
    I have the same problem with Unity Netcode it works fine on the host but it does not work on the client side.