Matchmaking doesn't work Photon Fusion

Options
kroko
kroko
edited April 2022 in Fusion

Im trying to make a simple room system in photon fusion. However I ran into a problem, when I try to start a client after joining a session i get an error.

Here is the object that handles all of the matchmaking.

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using Fusion;

using TMPro;

using Fusion.Sockets;

using System;


public class Connecting : MonoBehaviour, INetworkRunnerCallbacks

{

  public void OnPlayerJoined(NetworkRunner runner, PlayerRef player)   

  {

    Debug.Log("a new Player");

  }

  public void OnPlayerLeft(NetworkRunner runner, PlayerRef player) { }

  public void OnInput(NetworkRunner runner, NetworkInput input) { }

  public void OnInputMissing(NetworkRunner runner, PlayerRef player, NetworkInput input) { }

  public void OnShutdown(NetworkRunner runner, ShutdownReason shutdownReason) { }

  public void OnConnectedToServer(NetworkRunner runner) { }

  public void OnDisconnectedFromServer(NetworkRunner runner) { }

  public void OnConnectRequest(NetworkRunner runner, NetworkRunnerCallbackArgs.ConnectRequest request, byte[] token) { }

  public void OnConnectFailed(NetworkRunner runner, NetAddress remoteAddress, NetConnectFailedReason reason) { }

  public void OnUserSimulationMessage(NetworkRunner runner, SimulationMessagePtr message) { }

  public void OnSessionListUpdated(NetworkRunner runner, List<SessionInfo> sessionList) { }

  public void OnCustomAuthenticationResponse(NetworkRunner runner, Dictionary<string, object> data) { }

  public void OnHostMigration(NetworkRunner runner, HostMigrationToken hostMigrationToken) { }

  public void OnReliableDataReceived(NetworkRunner runner, PlayerRef player, ArraySegment<byte> data) { }

  public void OnSceneLoadDone(NetworkRunner runner) { }

  public void OnSceneLoadStart(NetworkRunner runner) { }


  public string roomID;

  public TMP_InputField startInput; 

  public TMP_InputField joinInput;

  public TMP_InputField NickNameInput;

  bool nickProvided = false;

  public string nick;

  private string randomNick;

  // Start is called before the first frame update

  void Start()

  {

    DontDestroyOnLoad(gameObject);

    randomNick = UnityEngine.Random.Range(1f, 99f).ToString();

  }

  private void Update()

  {

    if (NickNameInput.text == ""|| NickNameInput.text==null || NickNameInput.text== " ")

    {

      nickProvided = false;

    }

    else

    {

      nickProvided = true;

    }

    if (nickProvided == false)

    {

      nick = randomNick;

    }

    //NickName

    nick = NickNameInput.text;

  }

  public void StartHost(NetworkRunner runner)

  {


    runner.StartGame(new StartGameArgs()

    {

      GameMode = GameMode.Host,

      SessionName = startInput.text,

      CustomLobbyName = startInput.text


    });

    Debug.Log(runner.SessionInfo.PlayerCount);

    Debug.Log(runner.SessionInfo.Name);

    Debug.Log(runner.SessionInfo.IsValid);

    Debug.Log(runner.SessionInfo.IsOpen);

  }

  public void JoinLobby(NetworkRunner runner)

  {

    runner.JoinSessionLobby(SessionLobby.Custom, joinInput.text);

    runner.StartGame(new StartGameArgs()

    {

      GameMode = GameMode.Client,

      SessionName = runner.SessionInfo.Name


    });

    Debug.Log(runner.SessionInfo.Name);

  }

}

Here is all the code im using to handle matchmaking.

The game works fine when I try to host a game however when I try to join the same game from the build i get an error. I also get the same error even if the room im trying to join doesnt exist. The error occures as soon as it read this

 runner.StartGame(new StartGameArgs()

    {

      GameMode = GameMode.Client,

      SessionName = runner.SessionInfo.Name

    });

Pls help

Best Answer

  • kroko
    kroko
    Answer ✓
    Options

    At first I thought this didn't solve my problem since I already tried replacing

    SessionName = runner.SessionInfo.Name

    with a fixed string and that didn't help since I was getting the same error. But of all the three links you provided I realized that I haven't visited the Fusion 102 (Basic setup for host), and there I found the solution!

    Thank you for your help!

Answers