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);
}
}