Skip to content

Conversation

@Anduil
Copy link

@Anduil Anduil commented Dec 3, 2025

Fixes #4070

When calling [Command] on server-owned objects from host, the sender NetworkConnection parameter is null. This was working before commit b980ea4 and the fix in PR #4063 did not fully resolve the issue in this case.

Changes

  • For host-only fill the NetworkConnection sender parameter using NetworkServer.localConnection instead of this.connectionToClient.

Notes

  • I also added a test that now passes with this fix. Before the change, the same test would fail.
  • P.S. This is just one possible solution to the problem. My understanding of Mirror’s overall architecture is not 100%, so there may be more appropriate ways to fix this.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes issue #4070 where calling a [Command] on server-owned objects from the host resulted in a null sender connection parameter. The fix changes the command weaver to pass NetworkServer.localConnection (representing the host client's connection) instead of this.connectionToClient (which is null for server-owned objects) when executing commands in host mode.

Key changes:

  • Updated the command weaver to use NetworkServer.localConnection as the sender connection in host mode
  • Added a new test case verifying that server-owned objects receive a non-null connection parameter
  • Renamed an existing test for clarity

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
Assets/Mirror/Editor/Weaver/WeaverTypes.cs Added reference to NetworkServer.localConnection property for use in code generation
Assets/Mirror/Editor/Weaver/Processors/CommandProcessor.cs Changed command parameter injection to use NetworkServer.localConnection instead of this.connectionToClient, correctly representing the calling client in host mode
Assets/Mirror/Tests/Editor/NetworkServer/NetworkServerTest.cs Renamed test for client-owned objects and added new test for server-owned objects to verify the fix

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

@tigran-sargsyan-w tigran-sargsyan-w left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey,

Nice catch on the host/server-owned case – using NetworkServer.localConnection here reads correctly to me and matches the intent of treating the host as a client better than relying on connectionToClient when it’s null.

I also really like that you added a focused test for this scenario and renamed the existing one — it makes the regression story clear and keeps the intent of each test obvious.

Only small thought: it might be worth adding a short comment near the localConnection usage explaining why connectionToClient is null in this path, since that isn’t obvious if you don’t have the original issue / context open.

Apart from that, the change set is small, targeted and easy to follow. Looks good to me 👍

@MrGadget1024 MrGadget1024 added bug Something isn't working regression Something that stopped working. If possible include the version that worked labels Dec 23, 2025
@Anduil
Copy link
Author

Anduil commented Dec 24, 2025

Thanks for the review — much appreciated!

I’ve added a short comment next to the NetworkServer.localConnection usage explaining why connectionToClient is null in the host + server-owned case, so the reasoning is clear without needing the original context.

Glad the focused test and rename helped clarify the regression story. Thanks again for the careful feedback 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working regression Something that stopped working. If possible include the version that worked

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants