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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Network Manager on remove player

Discussion in 'Multiplayer' started by Nmck, Mar 22, 2016.

  1. Nmck

    Nmck

    Joined:
    Jul 10, 2015
    Posts:
    14
    Hello,

    I am currently creating a custom network manager, overriding a few methods to implement a player list.

    But every time I try to run, I receive an error:

    Assets/Netman.cs(20,30): error CS0505: `Netman.OnServerRemovePlayer(UnityEngine.Networking.NetworkConnection, PlayerController)': cannot override because `UnityEngine.Networking.NetworkManager.OnServerRemovePlayer(UnityEngine.Networking.NetworkConnection, UnityEngine.Networking.PlayerController)' is not a method

    Even though it is a method, http://docs.unity3d.com/ScriptReference/Networking.NetworkManager.OnServerRemovePlayer.html

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.Networking;
    4.  
    5. public class Netman : NetworkManager
    6. {
    7.  
    8.     public Players players;
    9.  
    10.     public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
    11.     {
    12.         base.OnServerAddPlayer(conn, playerControllerId);
    13.  
    14.         var newPlayer = conn.playerControllers[0].gameObject;
    15.  
    16.         players.AddPlayer(newPlayer);
    17.     }
    18.  
    19.     public override void OnServerRemovePlayer(NetworkConnection conn, PlayerController player)
    20.     {
    21.  
    22.         base.OnServerRemovePlayer(conn, player);
    23.     }
    24.  
    25.     public override void OnServerDisconnect(NetworkConnection conn)
    26.     {
    27.         foreach (var p in conn.playerControllers)
    28.         {
    29.             if (p != null && p.gameObject != null)
    30.             {
    31.                 players.RemovePlayer(p.gameObject);
    32.             }
    33.         }
    34.         base.OnServerDisconnect(conn);
    35.     }
    36. }
    Does anyone know what I'm doing wrong?

    Thanks
     
  2. FlyingHighUp

    FlyingHighUp

    Joined:
    Apr 23, 2012
    Posts:
    16
    Hey, did you figure it out?
     
  3. Oshroth

    Oshroth

    Joined:
    Apr 28, 2014
    Posts:
    99
    You seem to have a class called PlayerController which is obstructing UnityEngine.Networking.PlayerController so that is causing the compiler to use your PlayerController instead of the Networking.PlayerController for the function argument. You need to rename your PlayerController, place it in a namespace, or change the function header for OnServerRemovePlayer to
    Code (CSharp):
    1. public override void OnServerRemovePlayer(NetworkConnection conn, UnityEngine.Networking.PlayerController [URL='http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=player']player[/URL])
    The easiest thing to do would probably be rename your class, otherwise you would need to use the full class path for UnityEngine.Networking.PlayerController to prevent the compiler using the wrong PlayerController class.