Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question how to reset/set NetworkVariables on NetworkManager.Singleton.shutdown

Discussion in 'Netcode for GameObjects' started by KristenBoyGames, May 22, 2022.

  1. KristenBoyGames

    KristenBoyGames

    Joined:
    May 23, 2021
    Posts:
    38
    lets say that im in a game and i want to leave, i call the Network shutdown, but the NetworkVairables will still have their value. i cant just call a ServerRpc to reset them since it would do it for everyone. How do i do it?
     
  2. ClearDark

    ClearDark

    Joined:
    Aug 25, 2013
    Posts:
    14
    Process the server RPC only for the client id you wish to reset the value for.
     
  3. KristenBoyGames

    KristenBoyGames

    Joined:
    May 23, 2021
    Posts:
    38
    how do i do it?
     
  4. CosmoM

    CosmoM

    Joined:
    Oct 31, 2015
    Posts:
    204
    With an
    if
    to compare the LocalClientId of each client to that of the target, or, more efficiently, google "ClientRpcParams".
     
  5. itisMarcii_

    itisMarcii_

    Joined:
    Apr 5, 2022
    Posts:
    111
    Something like that should do the trick

    Method(ulong clientID) {
    foreach (var client in NetworkManager.Singleton.ConnectedClientsIds)
    {
    if(client == cliendID) //do something
    break;
    }
    }