Skip to content

Commit

Permalink
Merge branch 'fix/support_disabling_domain_reload' into feat/generic_…
Browse files Browse the repository at this point in the history
…networkbehaviour_types
  • Loading branch information
ShadauxCat committed Oct 2, 2023
2 parents d86c21d + de6837e commit eb96263
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,15 @@ internal void OnValidate()
}
}
}

void ModeChanged(PlayModeStateChange change)
{
if(IsListening && change == PlayModeStateChange.ExitingPlayMode)
{
// Make sure we are not holding onto anything in case domain reload is disabled
ShutdownInternal();
}
}
#endif

/// <summary>
Expand Down Expand Up @@ -524,6 +533,9 @@ private void Awake()
NetworkConfig?.InitializePrefabs();

UnityEngine.SceneManagement.SceneManager.sceneUnloaded += OnSceneUnloaded;
#if UNITY_EDITOR
EditorApplication.playModeStateChanged += ModeChanged;
#endif
}

private void OnEnable()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif

namespace Unity.Netcode
{
Expand All @@ -13,5 +16,24 @@ internal struct ILPPMessageProvider : INetworkMessageProvider
{
return __network_message_types;
}

#if UNITY_EDITOR
[InitializeOnLoadMethod]
public static void NotifyOnPlayStateChange()
{
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
}

public static void OnPlayModeStateChanged(PlayModeStateChange change)
{
if (change == PlayModeStateChange.ExitingPlayMode)
{
// Clear out the network message types, because ILPP-generated RuntimeInitializeOnLoad code will
// run again and add more messages to it.
__network_message_types.Clear();
}
}

#endif
}
}

0 comments on commit eb96263

Please sign in to comment.