Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question EntityNotFound (21404) Error at ApproveBackfillTicketAsync

Discussion in 'Matchmaker' started by youngwoocho02, Oct 28, 2023.

  1. youngwoocho02

    youngwoocho02

    Joined:
    Feb 8, 2019
    Posts:
    15
    there is error while trying

    Code (CSharp):
    1. await MatchmakerService.Instance.ApproveBackfillTicketAsync(backfillTicketID);
    this is full code
    Code (CSharp):
    1. private const string NA = "n/a";
    2.     public const int MAX_PLAYERS = 100;
    3.  
    4.  
    5.     private static string _allocationID;
    6.     private static bool _doBackFilling = false;
    7.     private static IServerQueryHandler _serverQueryHandler;
    8.     private static BackfillTicket _localBackfillTicket;
    9.     private static string _backfillTicketID;
    10.  
    11.     private static bool AllowEnter
    12.     {
    13.         get
    14.         {
    15.             return NetworkManager.Instances.ElementAt(0).ServerManager.Clients.Count < MAX_PLAYERS;
    16.         }
    17.     }
    18.  
    19.  
    20.     public static async void StartServer(string externalServerIP, ushort serverPort)
    21.     {
    22.         Debug.Log(nameof(StartServer));
    23.  
    24.         Debug.Log($"Init Server");
    25.         Camera.main.enabled = false;
    26.         QualitySettings.vSyncCount = 0;
    27.         Application.targetFrameRate = 30;
    28.  
    29.  
    30.         Debug.Log($"Start Server Connection");
    31.         var networkManager = NetworkManager.Instances.ElementAt(0);
    32.         networkManager.ServerManager.StartConnection(serverPort);
    33.         networkManager.ServerManager.OnRemoteConnectionState += OnRemoteConnectionState;
    34.  
    35.  
    36.         Debug.Log($"Start Server Services");
    37.         var option = new InitializationOptions();
    38.         option.SetEnvironmentName("production");
    39.         await UnityServices.InitializeAsync(option);
    40.  
    41.  
    42.         Debug.Log($"Start Server Query Handler");
    43.         var multiplayService = MultiplayService.Instance;
    44.         _serverQueryHandler = await multiplayService.StartServerQueryHandlerAsync(MAX_PLAYERS, "TestServer", NA, NA, NA);
    45.  
    46.  
    47.         Debug.Log("Ready Server For Players");
    48.         await multiplayService.ReadyServerForPlayersAsync();
    49.  
    50.  
    51.         Debug.Log("Get MatchMaker Payload");
    52.         var serverCallbacks = new MultiplayEventCallbacks();
    53.         serverCallbacks.Allocate -= OnMultiplayerAllocation;
    54.         serverCallbacks.Allocate += OnMultiplayerAllocation;
    55.         var sereverEvents = await multiplayService.SubscribeToServerEventsAsync(serverCallbacks);
    56.  
    57.  
    58.         var serverConfigs = multiplayService.ServerConfig;
    59.         Debug.Log($"Server ID[{serverConfigs.ServerId}]");
    60.         Debug.Log($"Server Allocation ID[{serverConfigs.AllocationId}]");
    61.         Debug.Log($"Server Port[{serverConfigs.Port}]");
    62.         Debug.Log($"Server Query Port[{serverConfigs.QueryPort}]");
    63.         Debug.Log($"Server Log Directory[{serverConfigs.ServerLogDirectory}]");
    64.  
    65.  
    66.         Debug.Log($"Wait for Allocation ID");
    67.         while (string.IsNullOrEmpty(_allocationID))
    68.         {
    69.             var configID = multiplayService.ServerConfig.AllocationId;
    70.  
    71.             if (string.IsNullOrEmpty(configID) == false && string.IsNullOrEmpty(_allocationID))
    72.             {
    73.                 Debug.Log($"Set Allocation ID With Config[{configID}]");
    74.                 _allocationID = configID;
    75.             }
    76.  
    77.             await UniTask.DelayFrame(100);
    78.         }
    79.  
    80.  
    81.         Debug.Log($"Get Payload Allocation");
    82.         var matchmakingResult = await MultiplayService.Instance.GetPayloadAllocationFromJsonAs<MatchmakingResults>();
    83.  
    84.         Debug.Log("Start Backfill Ticket");
    85.         var backfillProperties = new BackfillTicketProperties(matchmakingResult.MatchProperties);
    86.  
    87.         Debug.Log($"ID: {matchmakingResult.MatchId}, QueueName: {matchmakingResult.QueueName}, Properties: {backfillProperties}");
    88.         _localBackfillTicket = new BackfillTicket { Id = matchmakingResult.MatchId, Properties = backfillProperties };
    89.         _backfillTicketID = _localBackfillTicket.Id;
    90.  
    91.         Debug.Log("Start Backfilling");
    92.         _doBackFilling = true;
    93.         await TryBackFilling(networkManager, _backfillTicketID);
    94.         _doBackFilling = false;
    95.     }
    96.  
    97.     public static void UpdateServer()
    98.     {
    99.         if (_serverQueryHandler == null) { return; }
    100.  
    101.         if (NetworkManager.Instances.ElementAt(0).IsServer == false) { return; }
    102.  
    103.         _serverQueryHandler.CurrentPlayers = (ushort)NetworkManager.Instances.ElementAt(0).ServerManager.Clients.Count;
    104.  
    105.         _serverQueryHandler.UpdateServerCheck();
    106.     }
    107.  
    108.     private static async UniTask TryBackFilling(NetworkManager networkManager, string backfillTicketID)
    109.     {
    110.         Debug.Log(nameof(TryBackFilling));
    111.  
    112.         while (_doBackFilling && AllowEnter)
    113.         {
    114.             Debug.Log($"BackfillTicket ID: {backfillTicketID}");
    115.  
    116.             var matchmaker = MatchmakerService.Instance;
    117.             Debug.Log($"Matchmaker: {matchmaker}");
    118.  
    119.             var localBackfillTicket = await MatchmakerService.Instance.ApproveBackfillTicketAsync(backfillTicketID);
    120.             Debug.Log($"Local BackfillTicket ID: {localBackfillTicket.Id}");
    121.             backfillTicketID = localBackfillTicket.Id;
    122.  
    123.             await UniTask.DelayFrame(2000);
    124.         }
    125.     }
    126.  
    127.  
    128.     private static void OnRemoteConnectionState(NetworkConnection connection, RemoteConnectionStateArgs args)
    129.     {
    130.         Debug.Log(nameof(OnRemoteConnectionState));
    131.  
    132.         var networkManager = NetworkManager.Instances.ElementAt(0);
    133.  
    134.         switch (args.ConnectionState)
    135.         {
    136.             case RemoteConnectionState.Stopped:
    137.                 if (networkManager.ServerManager.Clients.Count == 0)
    138.                 {
    139.                     Debug.Log("Server Stopp by all clients disconnecting");
    140.                     Application.Quit();
    141.                     break;
    142.                 }
    143.  
    144.                 if (_doBackFilling == false && AllowEnter)
    145.                 {
    146.                     TryBackFilling(networkManager, _backfillTicketID).Forget();
    147.                 }
    148.                 break;
    149.         }
    150.     }
    151.  
    152.     private static void OnMultiplayerAllocation(MultiplayAllocation allocation)
    153.     {
    154.         Debug.Log(nameof(OnMultiplayerAllocation));
    155.  
    156.         Debug.Log($"Allocation ID [{allocation.AllocationId}]");
    157.         _allocationID = allocation.AllocationId;
    158.     }

    this is error message



    I spend too many time about this problem...
    if some body know answer plz help me
     
  2. youngwoocho02

    youngwoocho02

    Joined:
    Feb 8, 2019
    Posts:
    15
    fix error by using

    Code (CSharp):
    1. matchmakingResult.BackfillTicketId
     
  3. yogesh_unity255

    yogesh_unity255

    Joined:
    Jun 23, 2023
    Posts:
    2
  4. youngwoocho02

    youngwoocho02

    Joined:
    Feb 8, 2019
    Posts:
    15
    just use matchmakingResult.BackfillTicketId after allocation