diff --git a/Assets/Mirror/Runtime/NetworkIdentity.cs b/Assets/Mirror/Runtime/NetworkIdentity.cs index eb934916b..1a77d979c 100644 --- a/Assets/Mirror/Runtime/NetworkIdentity.cs +++ b/Assets/Mirror/Runtime/NetworkIdentity.cs @@ -129,19 +129,8 @@ internal set public NetworkBehaviour[] NetworkBehaviours { get; private set; } #pragma warning disable 618 - NetworkVisibility visibilityCache; [Obsolete(NetworkVisibilityObsoleteMessage.Message)] - public NetworkVisibility visibility - { - get - { - if (visibilityCache == null) - { - visibilityCache = GetComponent(); - } - return visibilityCache; - } - } + public NetworkVisibility visibility { get; private set; } #pragma warning restore 618 // current visibility @@ -287,6 +276,11 @@ internal void Awake() // => doing it here is the fastest and easiest solution. InitializeNetworkBehaviours(); + // initialize visibility component. only call GetComponent once. +#pragma warning disable 618 + visibility = GetComponent(); +#pragma warning restore 618 + if (hasSpawned) { Debug.LogError($"{name} has already spawned. Don't call Instantiate for NetworkIdentities that were in the scene since the beginning (aka scene objects). Otherwise the client won't know which object to use for a SpawnSceneObject message.");