Hello everybody,
So the hosting works fine, but the joining doesnt work. when i host from the editor (to see the join code), and try to join from the build nothing happens, so i added a join code display in the game scene, so i can host from the build to see the exception. and i get this every time i click the client button (even if the join code is correct/wrong):
here is my related code:
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class MainMenu : MonoBehaviour
{
[SerializeField] private TMP_InputField joinCodeField;
public async void StartHost()
{
await HostSingleton.Instance.GameManager.StartHostAsync();
}
public async void StartClient()
{
await ClientSingleton.Instance.GameManager.StartClientAsync(joinCodeField.text);
}
}
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
public class ClientSingleton : MonoBehaviour
{
private static ClientSingleton instance;
public ClientGameManager GameManager {get; private set; }
public static ClientSingleton Instance
{
get
{
if (instance != null) return instance;
instance = FindObjectOfType<ClientSingleton>();
if (instance = null)
{
Debug.LogError("No ClientSingelton found!!!!!!!!!!!");
return null;
}
return instance;
}
}
private void Start()
{
DontDestroyOnLoad(gameObject);
}
public async Task<bool> CreateClient()
{
GameManager = new ClientGameManager();
return await GameManager.InitAsync();
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using Unity.Netcode;
using Unity.Netcode.Transports.UTP;
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 JoinAllocation allocation;
private const string MenuSceneName = "Menu";
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 e)
{
Debug.Log(e);
return;
}
UnityTransport transport = NetworkManager.Singleton.GetComponent<UnityTransport>();
RelayServerData relayServerData = new RelayServerData(allocation, "dtls");
transport.SetRelayServerData(relayServerData);
NetworkManager.Singleton.StartClient();
}
}
i tried changing dtls to udp and its not working. i copy pasted the code from the repository and its not working. What it could be?
All the references are set correctly(host, client buttons, input fields etc.)