Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved NetworkManager make duplicates themselves

Discussion in 'Netcode for GameObjects' started by PiterQ70, Feb 20, 2022.

  1. PiterQ70

    PiterQ70

    Joined:
    Mar 3, 2015
    Posts:
    82
    Hi,
    So problem is that NetworkManager is default don't destroy on load but every time I load scene again it make another duplicate. How to fix it?
    Cheers
     
    Cathair likes this.
  2. ManuelRauber

    ManuelRauber

    Joined:
    Apr 3, 2015
    Posts:
    114
    Put the NetworkManager not into your GameScene but another scene that is loaded first and only once.
     
    RunninglVlan, Devseba and Cathair like this.
  3. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    358
    Yes, take the boss room as an example, they have the initial startup scene which then loads the main menu handling all the needed connection tasks etc. there.
     
    Cathair likes this.
  4. PiterQ70

    PiterQ70

    Joined:
    Mar 3, 2015
    Posts:
    82
    Thank you guys. Booss Room help me understand how to fix this problem.
    Cheers
     
    Cathair and ManuelRauber like this.
  5. Rito335

    Rito335

    Joined:
    Apr 4, 2021
    Posts:
    1
    Just check if NetworkManager singleton is not null and if that´s the case just instantiate it.

    Code (CSharp):
    1. [SerializeField] private GameObject NetworkManagerPrefab;
    2.  
    3. void Awake()
    4. {
    5.     if(NetworkManager.Singleton == null)
    6.         Instantiate(NetworkManagerPrefab);
    7.  
    8.     //DontDestroyOnLoad(gameObject);
    9. }