NetworkManager.OnClientConnect is obsolete


I am following along and it seems that mirror has been updated a bit. This course is out of date some. The video I am watching is the NetworkManager where we try to inherit from NetworkManager. What would be the correct solution for this?

2 Likes

Hi there,
The error says to replace NetworkConnection with NetworkClient.connection as the parameter. Can you try making this change and see if it gets rid of the error?

Thank you for getting back to me. That wont work because its NetworkClient.connection is a static class. OnClientConnect doesnt take any parameters. I was able to get this to work by doing the following.

using Mirror;
using UnityEngine;

public class MyNetworkManager : NetworkManager
{
    public override void OnClientConnect()
    {
        base.OnClientConnect();
        
    }


    public override void OnServerAddPlayer(NetworkConnection networkConnection)
    {
        base.OnServerAddPlayer(networkConnection);
        
        MyNetworkPlayer player = networkConnection.identity.GetComponent<MyNetworkPlayer>();
        
        Color displayColor = new Color(
            Random.Range(0f, 1f), 
            Random.Range(0f, 1f),
            Random.Range(0f, 1f));
        
        player.SetDisplayName($"Player {numPlayers}");
        player.SetDisplayColor(displayColor);
       
    }
    
    
    public override void OnServerDisconnect(NetworkConnection conn)
    {
        base.OnServerDisconnect(conn);
        Debug.Log("Bye!");

    }
    
}

5 Likes

Read about Script templates here Script Templates - Mirror

1 Like

Privacy & Terms