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. Dismiss Notice

Question When I try to access player from Unity Lobby code breaks.

Discussion in 'Lobby' started by CalorieIntake, Jul 25, 2023.

  1. CalorieIntake

    CalorieIntake

    Joined:
    Jul 7, 2023
    Posts:
    2
    I had a previously perfect project running but after some time, when I would run the code, the player class would always be null. So I wrote a sample to test this and here is the code that breaks when I run it. Any tips would be helpful because I'm very new around here.

    Code (CSharp):
    1. private async void ListLobbies()
    2.     {
    3.         try
    4.         {
    5.             QueryResponse queryresponse = await Lobbies.Instance.QueryLobbiesAsync();
    6.  
    7.  
    8.             Debug.Log("" + queryresponse.Results[0].Name + " " +  queryresponse.Results[0].Players[0].Data["PlayerName"].Value);
    9.             Debug.Log("Line 101 Lobbies Found: " + queryresponse.Results.Count);
    10.         }
    11.         catch
    12.         {
    13.  
    14.         }
    15.     }
    Additional details include that this works perfectly fine when I don't try to print ANYTHING remote about the player and when I switch the two debug statements, the second debug statement with the "queryresponse.Results[0].Players[0].Data["PlayerName"].Value" does not run. That is unless I remove anything about the player.

    Also this function "ListLobbys" is being called in a fixed update after the user signs in anonymously. Then I have a function that instantiates the player and passes it to a create lobby function with a create lobby options array and I pass in the value of this "GetPlayer" function.

    Code (CSharp):
    1. public Player GetPlayer()
    2.     {
    3.         return new Player
    4.         {
    5.             Data = new Dictionary<string, PlayerDataObject> { {"PlayerName", new         PlayerDataObject(PlayerDataObject.VisibilityOptions.Public, "James")} }
    6.         };
    7.     }
    I am using Unity editor version 2022.3.4f1
    I have a Intel core i5
    16 Gbs DDR3 Memory

    I hope this was detailed enough and thanks for any support.
     
  2. bartj-unity

    bartj-unity

    Unity Technologies

    Joined:
    Sep 9, 2021
    Posts:
    25
    Could you post the full debug output? And when you say the code breaks, what does that mean exactly? Is it throwing an exception?
     
  3. CalorieIntake

    CalorieIntake

    Joined:
    Jul 7, 2023
    Posts:
    2
    Issue was an unwritten variable after I didn’t save and I went crazy over it. So there it is. It wasn’t passed into a function that was trying to access it. This just took forever to find