Search Unity

Question StopHost(), StopClient() and StopServer() missing

Discussion in 'Multiplayer' started by ppaulikelis, Oct 27, 2021.

  1. ppaulikelis

    ppaulikelis

    Joined:
    Jun 15, 2021
    Posts:
    3
    Hello,

    I am reading Netcode for GameObjects 1.0.0 documentation and I found this example: https://docs-multiplayer.unity3d.com/docs/components/networkmanager/ (Disconnect section). I am trying to make disconnect button, but it seems like this example is outdated and I can't find how to Stop the Host or Client. What is the current method of doing this?

    Code (CSharp):
    1. public void Leave()
    2.     {    
    3.         if (NetworkManager.Singleton.IsHost)
    4.         {
    5.             NetworkManager.Singleton.StopHost();
    6.             NetworkManager.Singleton.ConnectionApprovalCallback -= ApprovalCheck;
    7.         }
    8.         else if (NetworkManager.Singleton.IsClient)
    9.         {
    10.             NetworkManager.Singleton.StopClient();
    11.         }
    12.  
    13.         connectionPannel.SetActive(true);
    14.         leaveButton.SetActive(false);
    15.     }
     
  2. prestsauce

    prestsauce

    Joined:
    Sep 15, 2018
    Posts:
    1
    I'm running into this too.

    From the 2021-10-19 changelog:

    Removed NetworkManager's StopServer(), StopClient() and StopHost() methods and replaced with single NetworkManager.Shutdown() method for all (#1108)

    I've replaced the methods with the Shutdown() method, now when a client disconnects, client-owned gameobjects are not unspawning automatically. I'm wondering if this is a bug or if I'm just misunderstanding the documentation.

    Any help on the spawning issue would be appreciated.
     
    b4guw1x, ProGameDevUser and Vhaldir like this.
  3. Tiberius226

    Tiberius226

    Joined:
    Dec 11, 2023
    Posts:
    1


    You have to uncheck "Don't destroy with owner from the NetworkObject script attached to the player prefab(assuming you have one).
     
    b4guw1x likes this.