mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
feat: Prevent Nested Network Managers (see #2867)
This commit is contained in:
parent
8ca5203262
commit
966af93e50
@ -141,6 +141,20 @@ public class NetworkManager : MonoBehaviour
|
||||
// virtual so that inheriting classes' OnValidate() can call base.OnValidate() too
|
||||
public virtual void OnValidate()
|
||||
{
|
||||
// make sure someone doesn't accidentally add another NetworkManager
|
||||
// need transform.root because when adding to a child, the parent's
|
||||
// OnValidate isn't called.
|
||||
foreach (NetworkManager manager in transform.root.GetComponentsInChildren<NetworkManager>())
|
||||
{
|
||||
if (manager != this)
|
||||
{
|
||||
Debug.LogError($"{name} detected another component of type {typeof(NetworkManager)} in its hierarchy on {manager.name}. There can only be one, please remove one of them.");
|
||||
// return early so that transport component isn't auto-added
|
||||
// to the duplicate NetworkManager.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// add transport if there is none yet. makes upgrading easier.
|
||||
if (transport == null)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user