From 8adede43a2590a8009f3881d5f4b6957e7a65a23 Mon Sep 17 00:00:00 2001 From: vis2k Date: Wed, 26 May 2021 14:19:13 +0800 Subject: [PATCH] NetworkIdentity.visibility: assign from Awake instead of lazy get --- Assets/Mirror/Runtime/NetworkIdentity.cs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) 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.");