Skip to content

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

@Anduil

Description

@Anduil

After commit b980ea4 (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:
NetworkServer.Spawn(globalObj); // no owner
  1. On each client (and host-client), call a Command from OnStartClient.
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
    }
}
  1. 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 b980ea4.


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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions