Skip to content

Commit a81bdf1

Browse files
update
Adding OnInstantiated and OnDestroying events to NetworkManager in order to provide the ability to know when a new NetworkManager instance has been instantiated and is being destroyed.
1 parent cb7ec98 commit a81bdf1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ namespace Unity.Netcode
1717
[AddComponentMenu("Netcode/Network Manager", -100)]
1818
public class NetworkManager : MonoBehaviour, INetworkUpdateSystem
1919
{
20+
/// <summary>
21+
/// Subscribe to this static event to get notifications when a <see cref="NetworkManager"/> instance has been instantiated.
22+
/// </summary>
23+
public static event Action<NetworkManager> OnInstantiated;
24+
25+
/// <summary>
26+
/// Subscribe to this static event to get notifications when a <see cref="NetworkManager"/> instance is being destroyed.
27+
/// </summary>
28+
public static event Action<NetworkManager> OnDestroying;
29+
30+
2031
#if UNITY_EDITOR
2132
// Inspector view expand/collapse settings for this derived child class
2233
[HideInInspector]
@@ -1030,6 +1041,8 @@ private void Awake()
10301041
#if UNITY_EDITOR
10311042
EditorApplication.playModeStateChanged += ModeChanged;
10321043
#endif
1044+
// Notify we have instantiated a new instance of NetworkManager.
1045+
OnInstantiated?.Invoke(this);
10331046
}
10341047

10351048
private void OnEnable()
@@ -1632,6 +1645,9 @@ private void OnDestroy()
16321645

16331646
UnityEngine.SceneManagement.SceneManager.sceneUnloaded -= OnSceneUnloaded;
16341647

1648+
// Notify we are destroying NetworkManager
1649+
OnDestroying?.Invoke(this);
1650+
16351651
if (Singleton == this)
16361652
{
16371653
Singleton = null;

0 commit comments

Comments
 (0)