Closed f2069 closed 1 month ago
Had a similar issue myself, doubly-nested NetObjects did not get enabled on clientHost, the issue was that the SortRootAndNestedByInitializeOrder
function in ServerObjects.Observers.cs
did not include double-nested objects.
Try replacing it with this and see if it fixes your issue:
/// <summary>
/// Sorts a collection of NetworkObjects root and nested by initialize order.
/// Collection returned is a new cache and should be disposed of properly.
/// </summary>
internal List<NetworkObject> SortRootAndNestedByInitializeOrder(List<NetworkObject> nobs)
{
List<NetworkObject> sortedRootCache = CollectionCaches<NetworkObject>.RetrieveList();
//First order root objects.
foreach (NetworkObject item in nobs)
{
if (item.IsNested)
continue;
sortedRootCache.AddOrdered(item);
}
/* After all root are ordered check
* their nested. Order nested in segments
* of each root then insert after the root.
* This must be performed after all roots are ordered. */
List<NetworkObject> sortedRootAndNestedCache = CollectionCaches<NetworkObject>.RetrieveList();
List<NetworkObject> sortedNestedCache = CollectionCaches<NetworkObject>.RetrieveList();
List<NetworkObject> nestedToIterate = CollectionCaches<NetworkObject>.RetrieveList();
foreach (NetworkObject item in sortedRootCache)
{
nestedToIterate.AddRange(item.InitializedNestedNetworkObjects);
while(nestedToIterate.Count > 0) {
var iteratingNetObj = nestedToIterate[0];
sortedNestedCache.AddOrdered(iteratingNetObj);
sortedNestedCache.Add(iteratingNetObj);
nestedToIterate.RemoveAt(0);
nestedToIterate.InsertRange(0, iteratingNetObj.InitializedNestedNetworkObjects);
}
/* Once all nested are sorted then can be added to the
* sorted root and nested cache. */
sortedRootAndNestedCache.Add(item);
sortedRootAndNestedCache.AddRange(sortedNestedCache);
//Reset cache.
nestedToIterate.Clear();
sortedNestedCache.Clear();
}
//Store temp caches.
CollectionCaches<NetworkObject>.Store(sortedRootCache);
CollectionCaches<NetworkObject>.Store(sortedNestedCache);
return sortedRootAndNestedCache;
}
Resolved in 4.5.2
General Unity version: 2021.3.18f Fish-Networking version: 4.5.1R Pro Discord link: https://discord.com/channels/424284635074134018/1293374787032191008 Related: #791
Description When the game scene starts, the server spawned a prefab tower. Inside the tower there are 4 holders that rotate. Each holder instantiates a cube into an internal container on the server. If the client connects to the server after the game scene has been loaded, there are no nested cubes on the client, only one holder is active and all nested containers are inactive. I've also tried turning on ‘Synchronize Parent’ on the cube, but it didn't work.
Objects:
Replication
Expected behavior When the client connects to the server scene - all nested network objects are enabled and spawned as it does on the server.
Screenshots Now:
Expected:
Video: https://youtu.be/XxR9sYFpESY Package: NestedSpawn.Report.151024.unitypackage.zip
Spawn tower:
Spawn nested cube:
If the client connects to the scene together with the server, everything works correctly. Also in version 4.4.7 and earlier - everything worked fine.