Skip to content

Commit 8ed8666

Browse files
temp-fix
Temporary fix for automatically adding the NetworkObjectBridge and not causing warnings to be logged about sending messages during Awake, OnValidate, etc.
1 parent 5d9f741 commit 8ed8666

File tree

1 file changed

+19
-34
lines changed

1 file changed

+19
-34
lines changed

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

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,6 @@ internal void OnValidate()
276276
return;
277277
}
278278

279-
#if UNIFIED_NETCODE
280-
UnifiedValidation();
281-
#endif
282-
283279
// Get a global object identifier for this network prefab.
284280
var globalId = GlobalObjectId.GetGlobalObjectIdSlow(this);
285281

@@ -376,15 +372,22 @@ internal void UnifiedValidation()
376372
HasGhost = GhostAdapter != null;
377373
if (HasGhost && NetworkObjectBridge == null)
378374
{
375+
NetworkObjectBridge = gameObject.AddComponent<NetworkObjectBridge>();
376+
HadBridge = true;
377+
// Transform synchronization is handled by unified netcode
378+
SynchronizeTransform = false;
379+
380+
// Move the bridge to the top
381+
while (NetworkObjectBridge != null && UnityEditorInternal.ComponentUtility.MoveComponentUp(NetworkObjectBridge))
379382
{
380-
NetworkObjectBridge = gameObject.AddComponent<NetworkObjectBridge>();
381-
HadBridge = true;
382-
// Transform synchronization is handled by unified netcode
383-
SynchronizeTransform = false;
383+
// Keep moving until it can't go higher
384384
}
385385

386-
EditorApplication.delayCall += SortToTop;
387-
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+
}
388391
}
389392
else if (HadBridge && !HasGhost && !NetworkObjectBridge)
390393
{
@@ -393,31 +396,13 @@ internal void UnifiedValidation()
393396
}
394397
}
395398

396-
397-
private void SortToTop()
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()
398404
{
399-
if (gameObject == null)
400-
{
401-
return;
402-
}
403-
// Move the bridge to the top
404-
while (NetworkObjectBridge != null && UnityEditorInternal.ComponentUtility.MoveComponentUp(NetworkObjectBridge))
405-
{
406-
// Keep moving until it can't go higher
407-
}
408-
409-
// Now move the GhostAdapter to the top so it is above NetworkObjectBridge
410-
while (GhostAdapter != null && UnityEditorInternal.ComponentUtility.MoveComponentUp(GhostAdapter))
411-
{
412-
// Keep moving until it can't go higher
413-
}
414-
415-
if (gameObject != null)
416-
{
417-
EditorUtility.SetDirty(gameObject);
418-
return;
419-
}
420-
405+
UnifiedValidation();
421406
}
422407
#endif
423408
#endif

0 commit comments

Comments
 (0)