Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Unity Multiplayer How to use MatchAttributes?

Discussion in 'Multiplayer' started by Stratos-Mak, Jun 26, 2015.

  1. Stratos-Mak

    Stratos-Mak

    Joined:
    Aug 14, 2014
    Posts:
    11
    I am creating a game with the matchmaker, and populate it with game name, players etc...
    I want to use the match attributes field to store some more info about the game, as its description suggests.

    Here is how I use it:

    Code (CSharp):
    1.  
    2.         CreateMatchRequest create = new CreateMatchRequest();
    3.         create.name = *name here*
    4.         create.size = *size here*
    5.         create.password = *pass here*
    6.  
    7.         Dictionary<string,long> attributes = new Dictionary<string,long>();
    8.  
    9.         if(create.password == "")
    10.             attributes.Add("pass",0);
    11.         else
    12.             attributes.Add("pass",1);
    13.  
    14.         create.advertise = true;
    15.         create.matchAttributes = attributes;
    16.      
    17.         CreateMatch(create, OnMatchCreate);

    And here is how I parse it when I fetch the game from a client:

    Code (CSharp):
    1.  
    2.         MatchDesc match = matchList[selectedMatch.id];
    3.         long hasPassword=0;
    4.  
    5.         Dictionary<string,long> attributes = match.matchAttributes;
    6.  
    7.         if(attributes.TryGetValue("pass", out hasPassword)) {
    8.  
    9.             if(hasPassword == 0)
    10.                JoinMatch(match.networkId,"",OnMatchJoined);
    11.             else {
    12.                 joinPassPanel.SetActive(true);
    13.             }
    14.         }

    The problem is that the fetched match attributes variable from the MatchDesc object is NULL.

    Am I doing something wrong here ?

    Thanks in advance!
     
  2. hasseyg

    hasseyg

    Joined:
    Nov 16, 2013
    Posts:
    77
    Hi, I am having the same problem
     
  3. Stratos-Mak

    Stratos-Mak

    Joined:
    Aug 14, 2014
    Posts:
    11
    Still no answer :/