question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistent use of client/transport ids

See original GitHub issue

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: https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/blob/3d2c266a4dab4c1cb851479bd1b39f602777278a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs#L274

and then used in several places e.g. when passing the ownerClientId: https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/blob/3d2c266a4dab4c1cb851479bd1b39f602777278a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs#L946

on the other hand, NetworkObject uses NetworkManager.LocalClientId when comparing for ownership: https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/blob/3d2c266a4dab4c1cb851479bd1b39f602777278a/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs#L86

and NetworkManager.LocalClientId directly references the ServerClientId implemented by the transport: https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/blob/3d2c266a4dab4c1cb851479bd1b39f602777278a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs#L284-L287

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

Issue Analytics

  • State:closed
  • Created 8 months ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
NoelStephensUnitycommented, Jan 30, 2023

@FreshlyBrewedCode That does indeed look like it is returning the incorrect value. Let me double check as to why that is not returning the NGO layer client identifier, and if it is a mistake/bug I will get a PR up to fix that issue.
Thank you for pointing this out.

0reactions
NoelStephensUnitycommented, Jan 31, 2023
Read more comments on GitHub >

github_iconTop Results From Across the Web

Inconsistent import/use of package in frontend_client.go ...
If I generate a client the use of other clients is inconsistent. ... The id MUST be unique among all operations described in...
Read more >
Client export and import queries
Hi Gurus, We're planning to perform a client export from our production environment, and import it into our qa environment as a new...
Read more >
Running Easel on Raspberry Pi
I have this up and running right now. I use my PI for a lot of different things, one of which is the...
Read more >
IT22218: MQ-JMS client using automatic ...
When using the automatic client reconnection feature, the MQ classes for JMS will attempt to reinstate any connection and.
Read more >
RFC 3261 SIP: Session Initiation Protocol
SIP invitations used to create sessions carry session descriptions that allow participants to agree on a set of compatible media types.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found