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

GetLobbyData returns "" in Steamworks setting up steam lobby...???

Discussion in 'Multiplayer' started by Kinnith7, Oct 14, 2021.

  1. Kinnith7


    Jul 4, 2017
    Ok, I have been working on this for 2 days now and it's driving me crazy. Does anyone know why this happens please...

    This code works perfectly. It just sets a steam lobby data kvp and retrieves it. Both below methods are in a script called "Steam Lobby.cs" When I set and recall the kvp in the same method it works fine. But if I put the exact same code in another method in the exact same script it just returns an empty string "". Can anyone explain what I am doing wrong? Any help is greatly appreciated.

    Code (CSharp):
    2. using System;
    3. using UnityEngine;
    4. using Steamworks;
    6. public class SteamLobby : Monobehaviour
    7. {
    8. private CSteamID lobbyID;
    9. private CSteamID mySteamID;
    11. [I][bunch o stuff cut out for space, steam lobby calls are set up for LobbyCreated_t callback works fine][/I]
    13. private void OnSteamLobbyCreated(LobbyCreated_t callback) {      
    14.         // Get the Steam Lobby ID.
    15.         lobbyID = (CSteamID)callback.m_ulSteamIDLobby;
    17.         // Set the lobby creator as the captain and set his ID in the steam lobby data.
    18.         mySteamId = SteamUser.GetSteamID();
    19.         SteamMatchmaking.SetLobbyData(lobbyID, "captain", mySteamId.ToString());
    21.         // Recall the captain's ID to print it out.
    22.         string temp2 = SteamMatchmaking.GetLobbyData(lobbyID, "captain");
    23.         print($"The Captain's Steam ID is: {temp2}");
    24. }
    25. }
    OUTPUT: The Captain's Steam ID is: 76561197970793737 <--Working Perfectly!

    2nd Method in the exact same script with exact same syntax .. results in "" return???
    Code (CSharp):
    2. private void RecallAndPrintLobbyDataEntry(){
    4.         string temp2 = SteamMatchmaking.GetLobbyData(lobbyID, "captain");
    5.         print($"The Captain's Steam ID is: {temp2}");
    6. }
    OUTPUT: The Captain's Steam ID is: <--- Nada! Zero! Zip! Nuthin! grrrrrr. 8( Same code!
    Last edited: Oct 14, 2021
  2. Lurking-Ninja


    Jan 20, 2015
    Please hit the Edit link on your post and put your code in code tags like it is described here:

    It is unreadable otherwise.

    I suspect you are calling this
    method before the
    running so you don't have a
  3. Kinnith7


    Jul 4, 2017
    ah! thanks! I wondered how people did that with the code formatting.

    No, I am actually using a different method in the game. I just shortened it to show important part of the problem more clearly. The RecallAndPrintLobbyDataEntry method is called well after the lobbyID and my mySteamID is set. That's the strange thing. It works perfectly as long as I do the GetLobbyData in the same method, just not if I put it in another method. I also already have other kvp set in the LobbyCreated callback method that uses GetLobbyData just fine in any other method. I can have GetLobbyData calls in the same method with the call that is failing and the others recall thier values with no problems. So I know the lobbyID is set correctly. I set a kvp for a shipName in the LobbyCreated callback method and then recall it in any other method with no problem. It's just this call for the value of the "captain" that fails. I can't see anything wrong with the call and I don't understand why simply putting it in another method fails. I just wondered if anyone else had experience something similar and knew why. Thanks for responding.
  4. Kinnith7


    Jul 4, 2017
    Fixed...kinda. I think it has to do with the GetLobbyData and SetLobbyData actually using "const char*" instead of just regular string type. I just set the lobby up another way that doesn't rely on me having to try and store the CSteamID or PersonaName in the lobby data. Might also be a security issue with Steamworks not wanting to store and recall CSteamID and PersonaName in the lobby data. Just went about setting up my lobby a different way. Works fine now. Just putting this here in case anyone else stumbles upon this problem. Don't store CSteam.ToString() or PersonaName in lobby data.
  5. BlackstarWarrior


    Sep 8, 2021
    I've run into this issue as well albeit in a bit of a different manner. Calling GetLobbyData from another method is fine and returns the data (even if it's the steamId or persona details) as long as it is on the client that created a lobby. However when I join the lobby from a different client, the story is a bit different. The lobby is joined successfully with no errors or warnings of any kind, however when the LobbyEnter callback is triggered, if I try to access any lobby related data (i.e. GetLobbyData, GetLobbyOwner...) it's always empty.

    Having a look at the steamworks documentation, it says that this data should be accessible only once you've joined the lobby. It also states that if the LobbyEnter callback was called successfully that you've joined the lobby and that the data should now be accessible. So now I'm very confused as to why it seems to be behaving like the client is not in the lobby when trying to get the lobby data in the method which supposedly represents that you've joined the lobby successfully.

    Have you figured out at all why this issue was happening? If not, what was your alternative way of retrieving the hosts steam id when joining a lobby?
  6. Kinnith7


    Jul 4, 2017
    I know it's been a long time since I posted on this and I'm very sorry for the delay but I was away from my project for a while.
    Now that I am back and have learned A LOT more CSharp, this is what I do. I created a class called LobbyData and store all the variables that are needed for the lobby information in that class. Then I Json format that class, encode it and store it in the steam lobby data as just one SteamMatchmaking.SetLobbyData call. That way it encodes the data so that I can put anything I want in it without worrying about someone messing with it, it also reduces all my lobby set and get calls to just one call reducing lobby bandwidth usage by a lot as well. So all clients can get steam id's, names, whatever in just one simple call to SteamMatchmaking. Of course, if there are any lobby variables that are needed for lobby searching I still have to do them in single calls, but still, things look much nicer this way and I can store whatever I want.
  7. GaborL


    Oct 31, 2015
    If you call SteamMatchmaking.RequestLobbyData before JoinLobby, the data will be available in LobbyEntered callback.
    kilik128, armutcocuk and Claytonious like this.