-
-
Notifications
You must be signed in to change notification settings - Fork 782
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
SyncVar hooks and Sync[Collection] handlers firing during initial spawn #3097
Comments
there are a few options later.
|
This issue introduces all kinds of undesirable side effects. For example, when hooks are fired for initial spawn Current workaround I use to fix execution order and all side effects (perhaps it will help while this is not fixed): [SyncVar(hook = nameof(TestHook))] private int hookedSyncVar = 0;
private bool muteHooks = true;
private void TestHook(int oldVal, int newVal) {
if (muteHooks) return;
// Hook logic goes here
}
public override void OnStartClient() {
base.OnStartClient();
muteHooks = false;
if (hookedSyncVar != 0)
TestHook(0, hookedSyncVar);
} All of the observations and suggested workaround are from version 66.0.9. |
Virtually eliminates null refs with GO/NI/NB SyncVars by getting all objects into spawned dictionary before applying payloads and invoking hooks. - No change to normal spawning, only initial spawn - Uses and clears a static dictionary, so no garbage allocation See ticket #3097
#3097 (#3961) * fix(NetworkClient): Defer ApplySpawnPayload until OnObjectSpawnFinished Virtually eliminates null refs with GO/NI/NB SyncVars by getting all objects into spawned dictionary before applying payloads and invoking hooks. - No change to normal spawning, only initial spawn - Uses and clears a static dictionary, so no garbage allocation See ticket #3097 * Update NetworkClient.cs * Update Assets/Mirror/Core/NetworkClient.cs --------- Co-authored-by: mischa <16416509+miwarnec@users.noreply.github.com>
Currrently for initial spawn payload this happens:
Would be better to defer the calling of hooks and callbacks until OnObjectSpawnFinished instead of firing them randomly during the spawn phase.
Additionally, in OnObjectSpawnFinished, we have this, but I think CheckForLocalPlayer should be first for any given object, not last.
And finally, it would be ideal if we waited until end-of-frame before running OnObjectSpawnFinished so that Awake on everything we just spawned has had a chance to fire, where callback handlers can get wired up before we invoke them.
One more thing...
Now that we have Client To Server, SyncVars don't fire the hook on the owner. It may be that the owner gets the update, but since it already matches the value owner has, the hook would be suppressed as "not changed". I think if Client To Server is set and
hasAuthority
is true, we should fire the hook on the owner. Otherwise we need to document that it won't fire so users know what to expect.The text was updated successfully, but these errors were encountered: