Problem in Joining A Random Game Session in Photon Fusion

ChrisL
ChrisL
edited March 2023 in Fusion

hello I've been using the code in the photon fusion sample project Fusion Karts which was a kart racing game.

I modified a certain method in its GameLauncher class so I can use it for joining a random game session, but it only seem to always join the first session created in the lobby and not the other available sessions.

The problem arises when the first session is already in-game but the client is still always trying to join that game session.

The code goes like this.

public void JoinRandomRace()

  { 

    SetConnectionStatus(ConnectionStatus.Connecting);


    if (_runner != null)

      LeaveSession();


    GameObject go = new GameObject("Session");

    DontDestroyOnLoad(go);


    _runner = go.AddComponent<NetworkRunner>();

    _runner.ProvideInput = _gameMode != GameMode.Server;

    _runner.AddCallbacks(this);


    _pool = go.AddComponent<FusionObjectPoolRoot>();


    Debug.Log($"Created gameobject {go.name} - starting game");

    

    _runner.StartGame(new StartGameArgs

    { 

      GameMode = GameMode.Client,

      ObjectPool = _pool,

      SceneManager = _levelManager,

      PlayerCount = ServerInfo.GameMode == 0 ? ServerInfo.MaxUsers : ServerInfo.MinUsers

    });

  }

Comments

  • Hi ChrisL, Sorry for the delay.

    I suspect you're not closing the session when the game starts?

    Joining a random session will try to join the first session it's was able to, so if you're not closing the session, client's will keep trying to join.

    I believe it's something along these lines:

    // When don't expecting more clients to join
    Runner.SessionInfo.IsVisible = false;
    Runner.SessionInfo.IsOpen = false;
    

    Not sure about the syntaxes though.

    -----

    Isaac Augusto

    Photon Fusion Team