Skip to content

Commit fae403a

Browse files
fix: NetworkBehaviourEditor exception when using the inspector view while in play mode (#2641)
* fix This fixes an issue where CheckForNetworkObject would perform its check when in playmode. This only needs to perform the check when not in play mode. * style Updated comments to be a bit clearer on what was updated.
1 parent 6d461bf commit fae403a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

com.unity.netcode.gameobjects/Editor/NetworkBehaviourEditor.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,9 @@ public static Transform GetRootParentTransform(Transform transform)
345345
/// <param name="networkObjectRemoved">used internally</param>
346346
public static void CheckForNetworkObject(GameObject gameObject, bool networkObjectRemoved = false)
347347
{
348-
// If there are no NetworkBehaviours or no gameObject, then exit early
349-
if (gameObject == null || (gameObject.GetComponent<NetworkBehaviour>() == null && gameObject.GetComponentInChildren<NetworkBehaviour>() == null))
348+
// If there are no NetworkBehaviours or gameObjects then exit early
349+
// If we are in play mode and a user is inspecting something then exit early (we don't add NetworkObjects to something when in play mode)
350+
if (EditorApplication.isPlaying || gameObject == null || (gameObject.GetComponent<NetworkBehaviour>() == null && gameObject.GetComponentInChildren<NetworkBehaviour>() == null))
350351
{
351352
return;
352353
}

0 commit comments

Comments
 (0)