fix: Unify SyncVar and SyncCollection replay across host visibility, scene re-observation, and pooled respawn - #4118
MrGadget1024 with Copilot wants to merge 52 commits into
Conversation
|
@copilot Error: Assets/Mirror/Core/SyncDictionary.cs(371,42): error CS0103: The name 'newItem' does not exist in the current context |
Addressed in 485ce90. |
|
@copilot Fix errors related to failed tests |
Addressed in 7ee058b. |
|
@copilot Fix failed test |
Addressed in 52f22a7. |
Codecov Report❌ Patch coverage is ❌ Your patch check has failed because the patch coverage (74.94%) 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 #4118 +/- ##
==========================================
+ Coverage 42.22% 42.84% +0.61%
==========================================
Files 156 156
Lines 15100 15496 +396
==========================================
+ Hits 6376 6639 +263
- Misses 8724 8857 +133
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
@copilot Extend the new tests to move host client player out of AOI range, Assert that the test object is no longer observed, change the SyncVar value or make a change to the Sync Collection, Assert no hooks / actions, move host client player into range again, Assert hooks / actions invoked again the same as previously, e.g. same original oldValue as if the host client is seeing it for the first time again. |
|
@Lymdun We good now? |
|
@copilot In the Room example, there is a Spawner static class |
Addressed in 1fab2fc with the test follow-up in 310425d. Host-mode |
@MrGadget1024 re-ran all evals, all good now ✅ |
|
@copilot Update the Title and Description of this PR reflecting the goals we achieved and describing the work completed. |
Use this updated PR metadata: Title Description
Example behavior after this change: [SyncVar(hook = nameof(OnValueChanged))]
public int value = 42;
// Mutated before the host can observe it
value = 100;
value = 200;
// When the host first observes or re-observes the object:
// OnValueChanged(42, 200)That wording matches the behavior covered by the final test set and the host/remote example scenarios fixed in this PR. |
|
|
Please provide a more concrete example? |
|
@MrGadget1024 Sorry wasnt able to replicate it, but error message was where Edit: Nvm, might be bad suggestion. |
|
@GoToNightmare Unity (and Mirror) serialize enums perfectly, even those with non-int bases. We have our own examples that use |
|
@MrGadget1024 I mean unity out of the box doesnt support serialization for enum flags with undeling type long/ulong, and that error I got is exactly that. Mirror generated field But im not sure if u should care about it on mirrors side. |
|
@GoToNightmare I can reproduce it with the PlayerTest example. That's a Unity bug and should be reported as such. Annoying, but not a Mirror issue. I notice the inspector still works fine, and the flags work fine, it's erroneous error spam. EDIT: Apparently Unity isn't going to fix this...long standing issue that I hadn't run into before. |
SyncVar hooks and SyncCollection callbacks could diverge between host and remote clients when visibility, scene-object reuse, or pooled respawn got involved. This PR brings those paths back into alignment so observation-driven replay behaves consistently across host mode, remote clients, AOI hide/show, and runtime
UnSpawn/respawn reuse.Preserve correct SyncVar baselines
oldValuea fresh observer would.Defer host callbacks until actual observation
Replay re-observation as a fresh observation
Addactions again on re-observation, instead of remembering prior observation state.Handle pooled runtime-object reuse in host mode
NetworkServer.UnSpawn/respawn of pooled runtime objects now marks SyncVar hooks and SyncCollection replays pending before visibility is lost.RandomColor) and current SyncCollection contents again, even without AOI.Preserve server delta queues and avoid duplicate callbacks
Regression coverage
Example behavior after this change: