fix: SyncVar hooks only fire on host client respecting AOI#4107
Open
MrGadget1024 wants to merge 8 commits intomasterfrom
Open
fix: SyncVar hooks only fire on host client respecting AOI#4107MrGadget1024 wants to merge 8 commits intomasterfrom
MrGadget1024 wants to merge 8 commits intomasterfrom
Conversation
- Weaver generation also preserves oldValue for the hooks.
MrGadget1024
commented
Apr 2, 2026
Collaborator
Author
MrGadget1024
left a comment
There was a problem hiding this comment.
revert asmdef change
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (59.42%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #4107 +/- ##
==========================================
+ Coverage 42.92% 43.00% +0.08%
==========================================
Files 156 156
Lines 14859 14907 +48
==========================================
+ Hits 6378 6411 +33
- Misses 8481 8496 +15
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WIP - Do Not Merge
Fixes host mode SyncVar hooks to provide correct old values and respect AOI properly.
Problem
SyncVar hooks in host mode had two critical issues:
Root ### Cause
In host mode, the sequence was:
Solution
Core Changes
• Capture original values: Added mechanism to capture SyncVar values before OnStartServer() runs
• Use captured values in hooks: Modified deserialize methods to use captured originals as oldValue
• Respect AOI: Only fire hooks for objects visible to the host client (spawned check)
• Proper timing: Hooks fire during client deserialization, not server setters
Implementation Details
NetworkBehaviour.cs
• Added hostModeOriginalValues dictionary to store original values by dirtyBit
• Updated all 4 GeneratedSyncVarDeserialize* methods to accept ulong dirtyBit parameter
• Added logic to use captured values as actualPrevious in host mode
• Added AOI check: NetworkClient.spawned.ContainsKey(netIdentity.netId)
NetworkIdentity.cs
• Added CaptureHostModeOriginalValues() call before each comp.OnStartServer() in host mode
• Perfect timing ensures values are captured before server modifications
NetworkClient.cs
• Clear
hostModeOriginalValuesafter spawn completed• Remove from spawned in OnHostClientObjectHide
Weaver Changes
• SyncVarAttributeProcessor: Generated CaptureHostModeOriginalValues() method that captures each SyncVar with its dirtyBit as key
• NetworkBehaviourProcessor: Updated DeserializeField() to pass dirtyBit to deserialize methods
• WeaverTypes: Added references for hostModeOriginalValues dictionary operations
Test Changes
• Replaced test that expected double-firing of SyncVar hooks for host
Test Results
✅ Correct old values: All hooks show oldValue = Color.black (true original)
✅ AOI respected: Far cube hook only fires when player moves into range (17 seconds later)
✅ Proper timing: Hooks fire when objects become visible to host client
Files Modified
• NetworkBehaviour.cs
• NetworkIdentity.cs
• NetworkClient.cs
• SyncVarAttributeProcessor.cs
• NetworkBehaviourProcessor.cs
• WeaverTypes.cs
• SyncVarHookDeferralTests.cs