Skip to content

Commit 13ef013

Browse files
update
improving how NetworkObjectBridge is added and then sorted to the top with the GhostAdapter.
1 parent 8ed8666 commit 13ef013

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed

com.unity.netcode.gameobjects/Runtime/Components/Helpers/NetworkObjectBridge.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,33 @@ namespace Unity.Netcode
1414
/// </remarks>
1515
public partial class NetworkObjectBridge : GhostBehaviour
1616
{
17+
18+
#if UNITY_EDITOR
19+
[UnityEngine.HideInInspector]
20+
[UnityEngine.SerializeField]
21+
private bool m_Sorted = false;
22+
private void OnValidate()
23+
{
24+
// Sort only once when we have first been added.
25+
if (!m_Sorted)
26+
{
27+
while (UnityEditorInternal.ComponentUtility.MoveComponentUp(this))
28+
{
29+
// Keep moving until it can't go higher
30+
}
31+
var ghostAdapter = gameObject.GetComponent<GhostAdapter>();
32+
// Now move the GhostAdapter to the top so it is above NetworkObjectBridge
33+
while (ghostAdapter != null && UnityEditorInternal.ComponentUtility.MoveComponentUp(ghostAdapter))
34+
{
35+
// Keep moving until it can't go higher
36+
}
37+
38+
m_Sorted = true;
39+
}
40+
}
41+
#endif
42+
43+
1744
/// <summary>
1845
/// This is used to link <see cref="NetworkObject.SerializedObject"/> data to
1946
/// N4E-spawned hybrid prefab instances.

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

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ internal void OnValidate()
291291
// Always check for in-scene placed to assure any previous version scene assets with in-scene place NetworkObjects gets updated.
292292
CheckForInScenePlaced();
293293

294+
#if UNIFIED_NETCODE
295+
UnifiedValidation();
296+
#endif
297+
294298
// If the GlobalObjectIdHash value changed, then mark the asset dirty.
295299
if (GlobalObjectIdHash != oldValue)
296300
{
@@ -376,34 +380,13 @@ internal void UnifiedValidation()
376380
HadBridge = true;
377381
// Transform synchronization is handled by unified netcode
378382
SynchronizeTransform = false;
379-
380-
// Move the bridge to the top
381-
while (NetworkObjectBridge != null && UnityEditorInternal.ComponentUtility.MoveComponentUp(NetworkObjectBridge))
382-
{
383-
// Keep moving until it can't go higher
384-
}
385-
386-
// Now move the GhostAdapter to the top so it is above NetworkObjectBridge
387-
while (GhostAdapter != null && UnityEditorInternal.ComponentUtility.MoveComponentUp(GhostAdapter))
388-
{
389-
// Keep moving until it can't go higher
390-
}
391383
}
392384
else if (HadBridge && !HasGhost && !NetworkObjectBridge)
393385
{
394386
HadBridge = false;
395387
SynchronizeTransform = true;
396388
}
397389
}
398-
399-
/// <summary>
400-
/// TODO: This needs to be handled better.
401-
/// Temporary work-around for sorting and adding components.
402-
/// </summary>
403-
private void OnEnable()
404-
{
405-
UnifiedValidation();
406-
}
407390
#endif
408391
#endif
409392
/// <summary>

com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ internal void AuthorityLocalSpawn([NotNull] NetworkObject networkObject, ulong n
12781278
#if UNIFIED_NETCODE
12791279
if (networkObject.HasGhost)
12801280
{
1281-
networkObject.NetworkObjectBridge.NetworkObjectId.Value = networkObject.NetworkObjectId;
1281+
networkObject.NetworkObjectBridge.SetNetworkObjectId(networkObject.NetworkObjectId);
12821282
}
12831283
#endif
12841284

0 commit comments

Comments
 (0)