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

Question How to tell if a player who is awaiting connection approval is still connected?

Discussion in 'Game Server Hosting' started by jackward84, Jun 21, 2023.

  1. jackward84

    jackward84

    Joined:
    Jan 26, 2017
    Posts:
    87
    So I was facing issues with scene management and players loading in the same scene multiple times from the network manager. I traced this problem back to the fact that the client who was getting the issue was loading in before the networkscenemanager had finished its scene switch, which seems to cause a strange issue where the client will load the same scene multiple times.

    To solve this I decided to use ConnectionApproval, and set the client to Pending until the scene is fully loaded, to avoid the client facing this issue. However this has an additional problem: if you set a client's Pending status to True, then some seconds later set it to False, the client may have since disconnected, and the NetworkManager does not handle this gracefully. Instead, the next time ConnectionApprovals are checked, it will throw an exception that the player is no longer connected.

    OK, fine, I'll check whether the player is connected first using ConnectedClients. But no, this doesn't work either because connections awaiting approval are not in the ConnectedClient list. So how am I supposed to check if this client is still connected? You cannot use the disconnected event, because it doesn't fire unless the player was approved and connected in the first place.
     
  2. jackward84

    jackward84

    Joined:
    Jan 26, 2017
    Posts:
    87
    Might have solved my own question, can use NetworkManager.Singleton.PendingClients and check what client ids are in it.