mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
fix(InterestManagement): calling OnEnable multiple times doesn't show an error anymore
This commit is contained in:
parent
be6c6c7c64
commit
0cc4726728
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user