NetworkIdentity.visibility: assign from Awake instead of lazy get

This commit is contained in:
vis2k 2021-05-26 14:19:13 +08:00
parent a10cdd6cbf
commit 8adede43a2

View File

@ -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<NetworkVisibility>();
}
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<NetworkVisibility>();
#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.");