Search code examples
c#unity-game-engineunity-networking

is the networkserver connectionId like an list in unity?


Hi I have been thinking about this question for a bit now and can't seem to get an answer.
My question is. Is the networkServer connectionId like an list in unity c#?

I'm thinking like this. lets say we have two players connected to the server.

player_1 = connectionId 0   
player_2 = connectionId 1

what would happen if let's say player_1 disconnects. would that make player_2 move down to the first row and get the connectionId of player_1?

player_1 = disconnected(no connectionId then)  
player_2 = connectionId 0  

or would he stay at the same connectionId? and if so what would happen if a third player connects? would he be set in front of the line and take player_1's old connectionId?

player_3 = connectionId 0  
player_2 = connectionId 1  

or would he be set to the back of the line? and get a new connectionId

player_1 = disconnected(no connectionId then)  
player_2 = connectionId 1  
player_3 = connectionId 2

Solution

  • what would happen if let's say player_1 disconnects. would that make player_2 move down to the first row and get the connectionId of player_1?

    No.

    or would he stay at the same connectionId? and if so what would happen if a third player connects? would he be set in front of the line and take player_1's old connectionId?

    Each connection get a unique ID.

    Read the Documentation of an API whenever you are confused.

    Quote from the Doc:

    Unique identifier for this connection that is assigned by the transport layer.

    On a server, this Id is unique for every connection on the server. On a client this Id is local to the client, it is not the same as the Id on the server for this connection.

    So, the ID remains the-same when other NetworkConnection are connected or disconnected.

    The only time the value of NetworkConnection.connectionId may change is when the device/client disconnects and connects again. In this case, it is giving another id when it reconnects again but this should not affect devices/clients that are still connected. Their IDs should still remain the-same.