Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

ChatBehaviour.OnStartAuthority()': no suitable method found to override.

Discussion in 'Multiplayer' started by pata220, Jan 16, 2022.

  1. pata220

    pata220

    Joined:
    Jan 19, 2021
    Posts:
    2
    I am following a tutorial by dapper dino about using mirror chat system.(
    ) I followed to end but there is an error Assets\Chat\Scripts\ChatBehaviour.cs(14,26): error CS0115: 'ChatBehaviour.OnStartAuthority()': no suitable method found to override. I am using unity version 2021.2

    Code (CSharp):
    1.  
    2. using Mirror;
    3. using System;
    4. using TMPro;
    5. using UnityEngine;
    6.  
    7. public class ChatBehaviour : MonoBehaviour
    8. {
    9.     [SerializeField] private GameObject chatUI = null;
    10.     [SerializeField] private TMP_Text chatText = null;
    11.     [SerializeField] private TMP_InputField inputField = null;
    12.  
    13.     private static event Action<string> OnMessage;
    14.  
    15.     public override void OnStartAuthority()
    16.     {
    17.         chatUI.SetActive(true);
    18.  
    19.         OnMessage += HandleNewMessage;
    20.     }
    21.  
    22.     [ClientCallback]
    23.     private void OnDestroy()
    24.     {
    25.         if (!hasAuthority) { return; }
    26.  
    27.         OnMessage -= HandleNewMessage;
    28.     }
    29.  
    30.     private void HandleNewMessage(string message)
    31.     {
    32.         chatText.text += message;
    33.     }
    34.  
    35.     [Client]
    36.     public void Send(string message)
    37.     {
    38.         if (!Input.GetKeyDown(KeyCode.Return)) { return; }
    39.  
    40.         if (string.IsNullOrWhiteSpace(message)) { return; }
    41.  
    42.         CmdSendMessage(message);
    43.  
    44.         inputField.text = string.Empty;
    45.     }
    46.  
    47.     [Command]
    48.     private void CmdSendMessage(string message)
    49.     {
    50.         RpcHandleMessage($"[{connectionToClient.connectionId}]: {message}");
    51.     }
    52.  
    53.     [ClientRpc]
    54.     private void RpcHandleMessage(string message)
    55.     {
    56.         OnMessage?.Invoke($"\n{message}");
    57.     }
    58. }
    59.  
     
    aviv1620 likes this.
  2. pata220

    pata220

    Joined:
    Jan 19, 2021
    Posts:
    2
    oops, wrong video

    i mean this video, maybe
     
  3. unity_fevlrmBLFHVmMQ

    unity_fevlrmBLFHVmMQ

    Joined:
    Sep 17, 2021
    Posts:
    1
    just use NetworkConnectionToClient instead of NetworkConnection and the problem should be solved.
    public override void OnServerAddPlayer(NetworkConnectionToClient conn){}
     
  4. wesselvis06

    wesselvis06

    Joined:
    Feb 15, 2021
    Posts:
    3
    Its a monobehaviour, not NetworkBehaviour