explain SetupLocalConnection order properly

This commit is contained in:
vis2k 2019-12-30 18:43:13 +01:00
parent cfe9520f7c
commit 892acf272c

View File

@ -391,8 +391,30 @@ public virtual void StartHost()
{ {
OnStartHost(); OnStartHost();
// SetupLocalConnection needs to be called BEFORE StartServer // SetupLocalConnection needs to be called BEFORE StartServer:
// (https://github.com/vis2k/Mirror/pull/1249/) // https://github.com/vis2k/Mirror/pull/1249/
// -> this sets NetworkServer.localConnection.
// -> localConnection needs to be set before StartServer because:
// -> StartServer calls OnStartServer
// -> OnStartServer might spawn an object and set [SyncVar(hook="OnColorChanged")] object.color = green;
// -> this calls SyncVar.set (generated by Weaver), which has
// a custom case for host mode (because host mode doesn't
// get OnDeserialize calls, where SyncVar hooks are usually
// called):
//
// if (!SyncVarEqual(value, ref color))
// {
// if (NetworkServer.localClientActive && !getSyncVarHookGuard(1uL))
// {
// setSyncVarHookGuard(1uL, value: true);
// OnColorChangedHook(value);
// setSyncVarHookGuard(1uL, value: false);
// }
// SetSyncVar(value, ref color, 1uL);
// }
//
// -> localClientActive needs to be true, otherwise the hook
// isn't called in host mode!
NetworkClient.SetupLocalConnection(); NetworkClient.SetupLocalConnection();
if (StartServer()) if (StartServer())
{ {