Skip to content

Commit 6ee768f

Browse files
fix
This fixes the issue where spawning a prefab that is configured to be spawned with no observers just prior to synchronizing a client and showing the spawned object to the client about to be synchronized within a NetworkBehaviour attached to the newly spawn prefab instance would result in a duplicate creation of the same prefab instance due to NetworkShow being deferred until the end of the frame. This fix excludes any spawned NetworkObjects that have pending visibility for a client that is being synchronized.
1 parent bdcb40b commit 6ee768f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

com.unity.netcode.gameobjects/Runtime/SceneManagement/SceneEventData.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,12 @@ internal void AddSpawnedNetworkObjects()
324324
var distributedAuthoritySendingToService = m_NetworkManager.DistributedAuthorityMode && TargetClientId == NetworkManager.ServerClientId;
325325
foreach (var sobj in m_NetworkManager.SpawnManager.SpawnedObjectsList)
326326
{
327+
var spawnedObject = sobj;
328+
// Don't synchronize objects that have pending visibility as that will be sent as a CreateObjectMessage towards the end of the current frame
329+
if (TargetClientId != NetworkManager.ServerClientId && m_NetworkManager.SpawnManager.IsObjectVisibilityPending(TargetClientId,ref spawnedObject))
330+
{
331+
continue;
332+
}
327333
if (sobj.Observers.Contains(TargetClientId) || distributedAuthoritySendingToService)
328334
{
329335
m_NetworkObjectsSync.Add(sobj);

0 commit comments

Comments
 (0)