Skip to content

Commit

Permalink
fix: NetworkBehaviourEditor exception when using the inspector view w…
Browse files Browse the repository at this point in the history
…hile in play mode (Unity-Technologies#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.
  • Loading branch information
NoelStephensUnity authored Jul 25, 2023
1 parent 6d461bf commit fae403a
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,9 @@ public static Transform GetRootParentTransform(Transform transform)
/// <param name="networkObjectRemoved">used internally</param>
public static void CheckForNetworkObject(GameObject gameObject, bool networkObjectRemoved = false)
{
// If there are no NetworkBehaviours or no gameObject, then exit early
if (gameObject == null || (gameObject.GetComponent<NetworkBehaviour>() == null && gameObject.GetComponentInChildren<NetworkBehaviour>() == null))
// If there are no NetworkBehaviours or gameObjects then exit early
// 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)
if (EditorApplication.isPlaying || gameObject == null || (gameObject.GetComponent<NetworkBehaviour>() == null && gameObject.GetComponentInChildren<NetworkBehaviour>() == null))
{
return;
}
Expand Down

0 comments on commit fae403a

Please sign in to comment.