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.1k stars 430 forks source link

NetworkManager should warn when a duplicate exists (Singleton already non-null) #2949

Open CodeSmile-0000011110110111 opened 2 weeks ago

CodeSmile-0000011110110111 commented 2 weeks ago

Is your feature request related to a problem? Please describe.

It is very common to have NetworkManager object duplicated. Thus the singleton is no longer a single instance and all sorts of issues will occur.

As a consequence, it's commonplace to "recommend" destroying the NetworkManager object upon shutdown with who-knows-what kind of side-effects this may have.

In fact following the NGO manual will easily lead to the issue where NetworkManager gets duplicated.

The cause is really simple: loading another scene that contains a NetworkManager. The most common cause is actually "restarting the game" simply by loading the one and only scene again.

Describe the solution you'd like In the editor and debug builds a warning should be logged to the console. Perhaps even throwing an exception might be in order.

This message should include the cause (loading a scene with NetworkManager in it, but it could also be caused by instantiating a prefab with NetworkManager in it) and the resolution (add NetworkManager to a scene that will not be loaded again, add a launch scene if necessary).

Describe alternatives you've considered Educating users but alas, given that the NGO manual provides the basis it has been used in projects and tutorials everywhere and keeps spreading.