Unity-Technologies / com.unity.netcode.gameobjects

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.
MIT License
2.15k stars 435 forks source link

Could you remove that function from Netcode scripts or disable it in playmode? #3017

Closed Marc477 closed 3 months ago

Marc477 commented 3 months ago

There is a script in Netcode that makes my project lag a lot when playing from the Editor.

It's an editor script that just send some kind of Warning but it makes the whole game lag.

I did a post with more details here: https://discussions.unity.com/t/performance-spike-because-of-a-netcode-networkmanagerhelper-editor-script-any-way-to-disable-that/1505627

But basically it's its NetworkManagerHelper.cs this function

private static void EditorApplication_hierarchyChanged()
        {
            var allNetworkManagers = Resources.FindObjectsOfTypeAll<NetworkManager>();
            foreach (var networkManager in allNetworkManagers)
            {
                if (!networkManager.NetworkManagerCheckForParent())
                {
                    Singleton.CheckAndNotifyUserNetworkObjectRemoved(networkManager);
                }
            }
        }

I have a large scene with a lot of gameobjects, most have their scripts/components disabled so the performances are very good in the build. It's just that this function makes the game unplayable from the editor.

Maybe just add this at the start of the function?

if(Application.isPlaying)
    return;

I could edit it myself, its just that this requires copying netcode script in the project instead of using the package manager, and makes updating version more complex.