-
-
Notifications
You must be signed in to change notification settings - Fork 842
fix: #4070 Host called command has null sender connection when server owns object #4072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.localConnectionas 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>
tigran-sargsyan-w
left a comment
There was a problem hiding this 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 👍
|
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 👍 |
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
Notes