Search Unity

Resolved the server and client should have the same NetworkBehaviour instances

Discussion in 'Multiplayer' started by BrettusTheLettus, Feb 6, 2021.

  1. BrettusTheLettus

    BrettusTheLettus

    Joined:
    Aug 6, 2020
    Posts:
    15
    Hi Guys,

    Just running through my first Networking tutorials for Mirror and got an error:
    Code (CSharp):
    1. Found no receiver for incoming Command [-411249099] on Unit(Clone), the server and client should have the same NetworkBehaviour instances [netId=8].
    2. UnityEngine.Logger:Log (UnityEngine.LogType,object)
    3. Mirror.ILoggerExtensions:LogError (UnityEngine.ILogger,object) (at Assets/Mirror/Runtime/Logging/LogFactory.cs:82)
    4. Mirror.NetworkIdentity:HandleRemoteCall (int,int,Mirror.MirrorInvokeType,Mirror.NetworkReader,Mirror.NetworkConnectionToClient) (at Assets/Mirror/Runtime/NetworkIdentity.cs:1096)
    5. Mirror.NetworkServer:OnCommandMessage (Mirror.NetworkConnection,Mirror.CommandMessage) (at Assets/Mirror/Runtime/NetworkServer.cs:1007)
    6. Mirror.MessagePacker/<>c__DisplayClass6_0`2<Mirror.CommandMessage, Mirror.NetworkConnection>:<WrapHandler>b__0 (Mirror.NetworkConnection,Mirror.NetworkReader,int) (at Assets/Mirror/Runtime/MessagePacker.cs:120)
    7. Mirror.NetworkConnection:TransportReceive (System.ArraySegment`1<byte>,int) (at Assets/Mirror/Runtime/NetworkConnection.cs:251)
    8. Mirror.NetworkServer:OnDataReceived (int,System.ArraySegment`1<byte>,int) (at Assets/Mirror/Runtime/NetworkServer.cs:570)
    9. Mirror.TelepathyTransport:ProcessServerMessage () (at Assets/Mirror/Runtime/Transport/TelepathyTransport.cs:190)
    10. Mirror.TelepathyTransport:LateUpdate () (at Assets/Mirror/Runtime/Transport/TelepathyTransport.cs:144)
    11.  
    I have units spawning fine when I have a client+Host and then when I add a second client they only update one frame and cannot use the movement script:
    Code (CSharp):
    1. public class UnitMovement : NetworkBehaviour
    2. {
    3.     [SerializeField] private NavMeshAgent agent;
    4.     [SerializeField] private Camera mainCamera;
    5.    
    6.     #region Server
    7.     [Command]
    8.     private void CmdMove(Vector3 position)
    9.     {
    10.         if (!NavMesh.SamplePosition(position, out NavMeshHit hit, Mathf.Infinity, NavMesh.AllAreas)) { return; }
    11.         agent.SetDestination(hit.position);
    12.         Debug.Log("Moving to " + position);
    13.     }
    14.     #endregion
    15.     #region Client
    16.     public override void OnStartAuthority()
    17.     {
    18.         mainCamera = Camera.main;
    19.     }
    20.  
    21.     [ClientCallBack]
    22.     private void Update()
    23.     {
    24.         if (!hasAuthority) { return; }
    25.  
    26.         if (!Mouse.current.rightButton.wasPressedThisFrame) { return; }
    27.  
    28.         Ray ray = mainCamera.ScreenPointToRay(Mouse.current.position.ReadValue());
    29.  
    30.         if(!Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity)) { return; }
    31.  
    32.         CmdMove(hit.point);
    33.         Debug.Log("Sending " + hit.point + " to Server.");
    34.     }
    35.     #endregion
    36. }
    and my unit script:
    Code (CSharp):
    1. using Mirror;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.Events;
    6.  
    7. public class Unit : NetworkBehaviour
    8. {
    9.     [SerializeField] private UnityEvent onSelected = null;
    10.     [SerializeField] private UnityEvent onDeselected = null;
    11.  
    12.     #region Client
    13.     [Client]
    14.     public void Select()
    15.     {
    16.         if (!hasAuthority) { return;}
    17.         onSelected?.Invoke();
    18.     }
    19.  
    20.     [Client]
    21.     public void Deselect()
    22.     {
    23.         if (!hasAuthority) { return; }
    24.         onDeselected?.Invoke();
    25.     }
    26.     #endregion
    27. }
    28.  
    I have followed the tutorials exactly unless I miss configure something in the inspector. So I can send requests for movement but the CmdMove() never gets executed.
     
  2. BrettusTheLettus

    BrettusTheLettus

    Joined:
    Aug 6, 2020
    Posts:
    15
    Ah see, I must have deleted NetworkTransform component at some point. How Bazaar I did that?