Skip to content

Inconsistent use of client/transport ids #2395

Closed
@FreshlyBrewedCode

Description

@FreshlyBrewedCode

TLDR

Client and transport ids are getting mixed up. NetworkTransport.ServerClientId should be a transport id and NetworkManager.LocalClientId is a client id yet the current implementation uses them interchangebly.

Detailed description with context

I am currently building a custom transport and I ran into some problems regarding client ids. My transport does assign and use custom ids internally (i.e. transport ids) and in my current implementation the transport id for the server is not 0 but 2.
So naturally I used the following implementation in my implementation of NetworkTransport:

public override ulong ServerClientId => 2;

This implementation works fine and the messages are routed correctly to the server. However, I run into problems if a player is hosting a game. When the player prefab for the host is spawned it receives an incorrect owner id (always 0).

In particular the problem seems to be that the ServerClientId is hardcoded to 0 in NetworkManager:

and then used in several places e.g. when passing the ownerClientId:

HandleConnectionApproval(ServerClientId, response);

on the other hand, NetworkObject uses NetworkManager.LocalClientId when comparing for ownership:

public bool IsOwner => NetworkManager != null && OwnerClientId == NetworkManager.LocalClientId;

and NetworkManager.LocalClientId directly references the ServerClientId implemented by the transport:

public ulong LocalClientId
{
get => IsServer ? NetworkConfig.NetworkTransport.ServerClientId : m_LocalClientId;
internal set => m_LocalClientId = value;

So as far as I can tell, if the transport implementation returns another value than 0 for ServerClientId on the server side there will be an ownership issue with the player prefab for the host.

I think the real issue however is that currently client and transport ids are getting mixed up. NetworkTransport.ServerClientId is a transport id and NetworkManager.LocalClientId is a client id yet the currently implementation uses them interchangebly.

Btw. the workaround is to return a different ServerClientId on the server/client side in the implementation of the transport:

public override ulong ServerClientId => isHost ? 0 : serverTransportId;

OS: Win10
Netcode Version: 1.2.0
Unity Version: 2020.3.41f1

Metadata

Metadata

Labels

stat:importedStatus - Issue is tracked internally at Unitytype:bugBug Report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions