Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity Matchmaking - Room disappears after exactly 30 seconds

Discussion in 'Scripting' started by Elisabeth123, Aug 6, 2019.

  1. Elisabeth123

    Elisabeth123

    Joined:
    Feb 17, 2016
    Posts:
    13
    Hi,

    My room always disappears after 30 seconds. I made a test script to test it and its always after 30 sec that it tells me that noone is online:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Networking;
    5. using UnityEngine.Networking.Match;
    6. public class NetworkTest : MonoBehaviour
    7. {
    8.     float currentT = 0;
    9.     int count = 0;
    10.     // Start is called before the first frame update
    11.     void Start()
    12.     {
    13.         if (NetworkManager.singleton.matchMaker == null)
    14.         {
    15.             NetworkManager.singleton.StartMatchMaker();
    16.         }
    17.  
    18.         CreateRoom("blub", 3);
    19.     }
    20.  
    21.     // Update is called once per frame
    22.     void Update()
    23.     {
    24.         currentT += Time.deltaTime;
    25.         if (currentT > 1)
    26.         {
    27.             Debug.Log(count);
    28.             NetworkManager.singleton.matchMaker.ListMatches(0, 20, "", true, 0, 0, OnMatchList);//Todo: verify true
    29.            
    30.             currentT = 0;
    31.             count++;
    32.         }
    33.     }
    34.  
    35.     public void CreateRoom(string roomName, uint roomSize)
    36.     {
    37.         if (roomName != "" && roomName != null)
    38.         {
    39.             Debug.Log("Cerating Room: " + roomName + " with room for " + roomSize + " players");
    40.             NetworkManager.singleton.matchMaker.CreateMatch(roomName, roomSize, true, "", "", "", 0, 0, OnMatchCreate);
    41.         }
    42.     }
    43.  
    44.     public void OnMatchCreate(bool success, string extendedInfo, MatchInfo matchInfo)
    45.     {
    46.         Debug.Log("OnMatchCreate called");
    47.         Debug.LogFormat("NetworkManager OnMatchCreate Success:{0}, ExtendedInfo:{1}, matchInfo:{2}", success, extendedInfo, matchInfo);
    48.         if (success)
    49.         {
    50.             Debug.Log("Created Match");
    51.         }
    52.         else
    53.         {
    54.             Debug.LogError("Create match failed");
    55.         }
    56.     }
    57.  
    58.  
    59.  
    60.     public void OnMatchList(bool success, string extendedInfo, List<MatchInfoSnapshot> matches)
    61.     {
    62.    
    63.         if (!success || matches.Count == 0)
    64.         {
    65.             Debug.Log("Currently there is no one online.");
    66.             return;
    67.         }
    68.         else
    69.         {
    70.             Debug.Log("There is someone online");
    71.         }
    72.     }
    73. }
    74.  
    Can anyone tell me what I am doing wrong here? Thanks in advance!