when trying to make second lobby after leaving first one it gives error

I’m Using 1.2.0 for Netcode with GameObjects and 2022.3.13 version of unity. So I’m almost done with my multiplayer game but when i make one lobby, either leave the character select scene or later, that part doesn’t matter, leave that lobby and try to make a new lobby it cannot find my NetworkManager, when debugging it says it’s Null in this line NetworkManager.Singleton.GetComponent<UnityTransport>().SetRelayServerData(new RelayServerData(allocation, "dtls"));, I know it is because it cannot find it the second time because i delete the networkManager when going back to the main menu scene so i don’t have multiple which also gives a lot of errors. this is how i delete the networkManager on a different script:

 if (NetworkManager.Singleton != null)
{
     Destroy(NetworkManager.Singleton.gameObject);
}

and this is the full method for the first line (if more context is needed just tell me, didn’t think 300 lines of code was needed):

public async void createLobby(string lobbyName, bool isPrivate)
{
    onCreateLobbyStarted?.Invoke(this, EventArgs.Empty);
    try
    {
        joinedLobby = await LobbyService.Instance.CreateLobbyAsync(lobbyName, optionsScript.MAX_PLAYER_AMOUNT, new CreateLobbyOptions
        {
            IsPrivate = isPrivate,
        });

        Allocation allocation = await allocateRelay();

        string relayJoinCode = await GetRelayJoinCode(allocation);

        await LobbyService.Instance.UpdateLobbyAsync(joinedLobby.Id, new UpdateLobbyOptions
        {
            Data = new Dictionary<string, DataObject>
            {
                {KEY_RELAY_JOIN_CODE,
                    new DataObject(DataObject.VisibilityOptions.Member,
                    relayJoinCode)}
            }
        });
        NetworkManager.Singleton.GetComponent<UnityTransport>().SetRelayServerData(new RelayServerData(allocation, "dtls"));

        //Debug.Log("start Host");
        optionsScript.Instance.startHost();
        Loader.loadNetwork(Loader.Scene.characterSelect);
    } catch (LobbyServiceException e)
    {
        Debug.Log(e);
        onCreateLobbyFailed?.Invoke(this, EventArgs.Empty);
    }
}

Fix that! Destroying the singleton NetworkManager is a symptom (or any singleton for that matter).

The duplication occurs because most likely you have NetworkManager in your main menu scene. Right? Good. Because you load that scene once again after launch, and thus the NetworkManager creates a duplicate which also gets put into DontDestroyOnLoad. I recently opened an issue for NetworkManager to check against duplication because it’s a prevalent issue.

The solution is really simple: add a scene before main menu which has the NetworkManager in it, and never gets loaded again. This “launch” scene instantly loads the main menu. Hence, no duplication.

I do delete the NetworkManager, so that isn’t the issue, when i said : “i delete the networkManager when going back to the main menu scene so i don’t have multiple” i meant it cannot be the issue of having multiple NetworkManagers because it will be destroyed when going back to main menu, so that is fixed.
edit: I see where the confusing happens, i completely worded that sentence wrong. I meant that if I have 2 it also gives errors that it cannot get certains things because it’s on the wrong networkManager so that cannot be the solution, sorry for the confusion

Yes, it is! You are NOT supposed to destroy the NetworkManager. This isn‘t a supported workflow. Anything that happens after duplication or destroy is basically untested and if you look around, you‘ll see plenty of issues happening only to users who do so.