ITADN

Command sender still null on server-owned objects after PR #4063

#4070ClosedAnduil 创建于 2025-12-02
A
Anduilcommented
After commit [b980ea4](https://github.com/MirrorNetworking/Mirror/commit/b980ea4a62a8ee7b51de96e455df207b32b876c8) (the Command system rewrite), Commands that include a `NetworkConnectionToClient sender` parameter no longer receive a valid sender when the Command is executed on a **server-owned** object (scene object or spawned without an owner), even if the Command was legitimately invoked by a client and `requiresAuthority = false`. PR **#4063** fixed this for objects that have a valid `connectionToClient`, but the problem still remains for server-owned objects where `connectionToClient` is naturally `null`. Before the rewrite, this worked correctly: Commands called by clients on server-owned objects could receive the sender connection. --- ## **Reproduction** 1. Create a server-owned object: ```csharp NetworkServer.Spawn(globalObj); // no owner ``` 2. On each client (and host-client), call a Command from OnStartClient. ```csharp public class GlobalManager : NetworkBehaviour { public override void OnStartClient() { base.OnStartClient(); CmdRegisterClient(); // called from client-side of each client } [Command(requiresAuthority = false)] void CmdRegisterClient(NetworkConnectionToClient sender = null) { Debug.Log("Sender = " + sender); // <-- always null for host + server object } } ``` 3. Observe on the server: The `sender` is always `null` because the weaver still fills it with `this.connectionToClient`, which is `null` for server-owned objects. This happens even though the Command was called by a real client. --- ## **Expected** Commands with `requiresAuthority = false` should provide the calling client's connection as the sender, same as before commit **b980ea4a62a8**. --- ## **Actual** Commands on server-owned objects always receive `sender == null` after the rewrite. PR #4063 fixes this only when `connectionToClient` is non-null (player-owned or client-owned objects), but not for server-owned ones. --- P.S. I’m not entirely sure if my understanding of the root cause is 100% correct, and I apologize if any part of this description is inaccurate.
关闭于 2026-01-08 1 条评论