Skip to content

Commit fac0d6f

Browse files
fix: keep the bridge when a script adds it before the NetworkObject
NetworkObjectBridge.OnValidate queued a DestroyImmediate whenever no NetworkObject was present yet. Test helpers (and user scripts) add the bridge first, so the bridge was destroyed after the prefab was set up, breaking every unified hybrid test. The deferred call now checks again before destroying.
1 parent 6c4d6c2 commit fac0d6f

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,14 @@ private void OnValidate()
3131
var networkObject = GetComponent<NetworkObject>();
3232
if (networkObject == null)
3333
{
34-
// Remove the bridge if there is no NetworkObject
35-
EditorApplication.delayCall += () => DestroyImmediate(this, true);
34+
// Check again once the current operation finishes, since a script can add the bridge before the NetworkObject.
35+
EditorApplication.delayCall += () =>
36+
{
37+
if (this != null && GetComponent<NetworkObject>() == null)
38+
{
39+
DestroyImmediate(this, true);
40+
}
41+
};
3642
}
3743
else
3844
{

0 commit comments

Comments
 (0)