Client won't switch to game scene and disconnects after 10 seconds

Hello everybody,

I’m having a problem with joining the host.
When I try joining the host, the client window won’t change to the game scene.
On the host window, the second player gets displayed for 10 sec and then it disappears.
I then hosted the game with the build and joined via the unity game window.
It’s still the same, but there I could finally see the log…

It seems like it’s waiting for an connection approval, but I checked my NetworkManager and there the “Connection Approval” isn’t ticked…

Has anybody an idea what the problem may be?

Best regards,
Manuel

1 Like

So i changed the connection Typ back to “udp”. Which fixed the issue. But i also would like to now how to make it run with the initial typ.

Can you post your ClientGameManager.cs script so i can take a look please.

Hi,

@Painder: I tried to switch to udp, but sadly that also didn’t work out for me…

@Marc_Carlyon: Here is my ClientGameManager.cs :

using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Unity.Netcode.Transports.UTP;
using Unity.Netcode;
using Unity.Networking.Transport.Relay;
using Unity.Services.Core;
using Unity.Services.Relay;
using Unity.Services.Relay.Models;
using UnityEngine;
using UnityEngine.SceneManagement;

public class ClientGameManager
{
	private const string MenuSceneName = "Menu";
	private JoinAllocation allocation;

	public async Task<bool> InitAsync()
	{
		await UnityServices.InitializeAsync();
		AuthState authState = await AuthenticationWrapper.DoAuth();

		if(authState == AuthState.Authenticated)
		{
			return true;
		}

		return false;
	}

	public void GoToMenu()
	{
		SceneManager.LoadScene(MenuSceneName);
	}

	public async Task StartClientAsync(string joinCode)
	{
		try
		{
			allocation = await Relay.Instance.JoinAllocationAsync(joinCode);
		}
		catch (Exception ex)
		{
			Debug.Log(ex);
			return;
		}

		UnityTransport transport = NetworkManager.Singleton.GetComponent<UnityTransport>();
		RelayServerData relayServerData = new RelayServerData(allocation, "dtls");
		transport.SetRelayServerData(relayServerData);

		NetworkManager.Singleton.StartClient();
	}
}

I’m using Unity 2022.3.4f1 and all of the packages are up to date.

Thank you both for your help.

Best regards,
Manuel

Hi everybody,

after reading through the unity documentation (Use Relay with Netcode for GameObjects (NGO)) under the section " Authenticate a player" I finally found my problem.

Before the call

await AuthenticationService.Instance.SignInAnonymouslyAsync();

in the AuthenticationWrapper.cs I added this line…

await UnityServices.InitializeAsync();

… and now it somehow works. (even with DTLS encryption)
Still don’t quiet understand it, but if anybody else got the same problem, hopefully this should fix it.

Thank you all!

Best regards,
Manuel

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms