Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Fixed

- `NetworkManager` will now perform a proper shutdown when the domain is reloaded in play mode, instead of being left in some half-initialized state that leaks memory and socket handles. (#4068)
- Issue when FastBufferReader is attempting to read a string and all or a portion of the character count has already been read by user script, it could read a character length that results in a negative byte length which could result in an editor crash. (#4052)
- Issue where NetworkRigidbodyBase was not applying rotation correctly when using Rigidbody2D. (#4012)
- Issue where NetworkRigidbodyBase was always checking the 3D rigid body's interpolation mode when determining if it is kinematic and needs to put the rigid body to sleep and then switch to interpolation. (#4012)
Expand Down
21 changes: 21 additions & 0 deletions com.unity.netcode.gameobjects/Editor/NetworkManagerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ private static void InitializeOnload()
Singleton = new NetworkManagerHelper();

NetworkManager.NetworkManagerHelper = Singleton;

AssemblyReloadEvents.beforeAssemblyReload -= AssemblyReloadEvents_beforeAssemblyReload;
AssemblyReloadEvents.beforeAssemblyReload += AssemblyReloadEvents_beforeAssemblyReload;

EditorApplication.playModeStateChanged -= EditorApplication_playModeStateChanged;
EditorApplication.hierarchyChanged -= EditorApplication_hierarchyChanged;

Expand All @@ -55,6 +59,23 @@ private static void InitializeOnload()
};
}

private static void AssemblyReloadEvents_beforeAssemblyReload()
{
if (Application.isPlaying)
{
#if UNITY_2023_1_OR_NEWER

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NGOv2.X offers support from 6000.0 editor so I don't think this if is needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same check is used elsewhere in the same file, but happy to remove it if it's not needed.

@michalChrobot michalChrobot Jul 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, remove it. I guess we just missed some stuff to cleanup. I will follow up on it

var networkManager = Object.FindAnyObjectByType<NetworkManager>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We added our own static API that hides all the different mutations FindObjects has gone through over time.

Though I think rather than searching for all NetworkManagers, it'd be better if any started NetworkManager registers themselves to something so they can be shut down. Objects.FindAll can be slow, I'd rather avoid needing to make Domain reloads any slower.

Suggested change
var networkManager = Object.FindAnyObjectByType<NetworkManager>();
var networkManager = FindObjects.ByType<NetworkManager>();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified the code to use NetworkManager.Singleton instead.

#else
var networkManager = Object.FindObjectOfType<NetworkManager>();
#endif
if (networkManager != null && (networkManager.IsServer || networkManager.IsClient))
{
networkManager.Shutdown();
networkManager.ShutdownInternal();
}
}
}

private static void EditorApplication_playModeStateChanged(PlayModeStateChange playModeStateChange)
{
switch (playModeStateChange)
Expand Down