Skip to content

Commit 9ffd22b

Browse files
fix: improve networking warning messages [MTT-1293] (#1855)
* fix: improve networking warning messages Co-authored-by: Fatih Mar <[email protected]>
1 parent f30b75e commit 9ffd22b

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
3636
- Fixed issue where NetworkManager would continue starting even if the NetworkTransport selected failed. (#1780)
3737
- Fixed issue when spawning new player if an already existing player exists it does not remove IsPlayer from the previous player (#1779)
3838
- Fixed lack of notification that NetworkManager and NetworkObject cannot be added to the same GameObject with in-editor notifications (#1777)
39+
- Fixed parenting warning printing for false positives (#1855)
3940

4041
## [1.0.0-pre.6] - 2022-03-02
4142

com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,8 @@ private void OnNetworkPostLateUpdate()
12841284
NetworkMetrics.UpdateNetworkObjectsCount(SpawnManager.SpawnedObjects.Count);
12851285
NetworkMetrics.UpdateConnectionsCount((IsServer) ? ConnectedClients.Count : 1);
12861286
NetworkMetrics.DispatchFrame();
1287+
1288+
NetworkObject.VerifyParentingStatus();
12871289
}
12881290
SpawnManager.CleanupStaleTriggers();
12891291

com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -658,13 +658,7 @@ internal bool ApplyNetworkParenting()
658658

659659
if (!NetworkManager.SpawnManager.SpawnedObjects.ContainsKey(m_LatestParent.Value))
660660
{
661-
if (OrphanChildren.Add(this))
662-
{
663-
if (NetworkLog.CurrentLogLevel <= LogLevel.Normal)
664-
{
665-
NetworkLog.LogWarning($"{nameof(NetworkObject)} ({name}) cannot find its parent, added to {nameof(OrphanChildren)} set");
666-
}
667-
}
661+
OrphanChildren.Add(this);
668662
return false;
669663
}
670664

@@ -757,6 +751,27 @@ internal void MarkVariablesDirty()
757751
}
758752
}
759753

754+
// NGO currently guarantees that the client will receive spawn data for all objects in one network tick.
755+
// Children may arrive before their parents; when they do they are stored in OrphanedChildren and then
756+
// resolved when their parents arrived. Because we don't send a partial list of spawns (yet), something
757+
// has gone wrong if by the end of an update we still have unresolved orphans
758+
//
759+
760+
// if and when we have different systems for where it is expected that orphans survive across ticks,
761+
// then this warning will remind us that we need to revamp the system because then we can no longer simply
762+
// spawn the orphan without its parent (at least, not when its transform is set to local coords mode)
763+
// - because then you’ll have children popping at the wrong location not having their parent’s global position to root them
764+
// - and then they’ll pop to the correct location after they get the parent, and that would be not good
765+
internal static void VerifyParentingStatus()
766+
{
767+
if (NetworkLog.CurrentLogLevel <= LogLevel.Normal)
768+
{
769+
if (OrphanChildren.Count > 0)
770+
{
771+
NetworkLog.LogWarning($"{nameof(NetworkObject)} ({OrphanChildren.Count}) children not resolved to parents by the end of frame");
772+
}
773+
}
774+
}
760775
internal void SetNetworkVariableData(FastBufferReader reader)
761776
{
762777
for (int i = 0; i < ChildNetworkBehaviours.Count; i++)

0 commit comments

Comments
 (0)