diff --git a/Assets/Mirror/Core/InterestManagementBase.cs b/Assets/Mirror/Core/InterestManagementBase.cs index aef7a651a..8fed86860 100644 --- a/Assets/Mirror/Core/InterestManagementBase.cs +++ b/Assets/Mirror/Core/InterestManagementBase.cs @@ -9,24 +9,17 @@ namespace Mirror [HelpURL("https://mirror-networking.gitbook.io/docs/guides/interest-management")] public abstract class InterestManagementBase : MonoBehaviour { - // Configures InterestManagementBase in NetworkServer/Client - // Do NOT check for active server or client here. - // OnEnable must always set the static aoi references. - // make sure to call base.OnEnable when overwriting! - // Previously used Awake() + // initialize NetworkServer/Client .aoi. + // previously we did this in Awake(), but that's called for disabled + // components too. if we do it OnEnable(), then it's not set for + // disabled components. protected virtual void OnEnable() { - if (NetworkServer.aoi == null) - { - NetworkServer.aoi = this; - } - else Debug.LogError($"Only one InterestManagement component allowed. {NetworkServer.aoi.GetType()} has been set up already."); - - if (NetworkClient.aoi == null) - { - NetworkClient.aoi = this; - } - else Debug.LogError($"Only one InterestManagement component allowed. {NetworkClient.aoi.GetType()} has been set up already."); + // do not check if == null or error if already set. + // users may enabled/disable components randomly, + // causing this to be called multiple times. + NetworkServer.aoi = this; + NetworkClient.aoi = this; } [ServerCallback]