mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
fix: #3341 SyncLists can now be modified before spawning again
This commit is contained in:
parent
02218bda13
commit
8570afab94
@ -232,17 +232,25 @@ protected void InitSyncObject(SyncObject syncObject)
|
||||
// carefully check each mode separately to ensure correct results.
|
||||
// fixes: https://github.com/MirrorNetworking/Mirror/issues/3342
|
||||
|
||||
// normally we would check isServer / isClient here.
|
||||
// users may add to SyncLists before the object was spawned.
|
||||
// isServer / isClient would still be false.
|
||||
// so we need to check NetworkServer/Client.active here instead.
|
||||
|
||||
// host mode: any ServerToClient and any local client owned
|
||||
if (isServer && isClient) return syncDirection == SyncDirection.ServerToClient || isOwned;
|
||||
if (NetworkServer.active && NetworkClient.active)
|
||||
return syncDirection == SyncDirection.ServerToClient || isOwned;
|
||||
|
||||
// server only: any ServerToClient
|
||||
if (isServer) return syncDirection == SyncDirection.ServerToClient;
|
||||
if (NetworkServer.active)
|
||||
return syncDirection == SyncDirection.ServerToClient;
|
||||
|
||||
// client only: only ClientToServer and owned
|
||||
if (isClient) return syncDirection == SyncDirection.ClientToServer && isOwned;
|
||||
if (NetworkClient.active)
|
||||
return syncDirection == SyncDirection.ClientToServer && isOwned;
|
||||
|
||||
// undefined behaviour should throw to make it very obvious
|
||||
throw new Exception("InitSyncObject: IsWritable: neither isServer nor isClient are true.");
|
||||
throw new Exception("InitSyncObject: IsWritable: neither NetworkServer nor NetworkClient are active.");
|
||||
};
|
||||
|
||||
// when do we record changes:
|
||||
@ -266,8 +274,10 @@ protected void InitSyncObject(SyncObject syncObject)
|
||||
// client only: only ClientToServer and owned
|
||||
if (isClient) return syncDirection == SyncDirection.ClientToServer && isOwned;
|
||||
|
||||
// undefined behaviour should throw to make it very obvious
|
||||
throw new Exception("InitSyncObject: IsRecording: neither isServer nor isClient are true.");
|
||||
// users may add to SyncLists before the object was spawned.
|
||||
// isServer / isClient would still be false.
|
||||
// in that case, allow modifying but don't record changes yet.
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -794,6 +794,9 @@ public void GetSyncVarNetworkIdentityOnClientNull()
|
||||
[Test]
|
||||
public void SerializeAndDeserializeObjectsAll()
|
||||
{
|
||||
NetworkServer.Listen(1);
|
||||
ConnectHostClientBlockingAuthenticatedAndReady();
|
||||
|
||||
CreateNetworked(out GameObject _, out NetworkIdentity _, out NetworkBehaviourWithSyncVarsAndCollections comp);
|
||||
|
||||
comp.netIdentity.isServer = true;
|
||||
|
Loading…
Reference in New Issue
Block a user