Search Unity

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

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

  1. Kinnith7

    Kinnith7

    Joined:
    Jul 4, 2017
    Posts:
    84
    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):
    1.  
    2. using System;
    3. using UnityEngine;
    4. using Steamworks;
    5.  
    6. public class SteamLobby : Monobehaviour
    7. {
    8. private CSteamID lobbyID;
    9. private CSteamID mySteamID;
    10.  
    11. [I][bunch o stuff cut out for space, steam lobby calls are set up for LobbyCreated_t callback works fine][/I]
    12.  
    13. private void OnSteamLobbyCreated(LobbyCreated_t callback) {      
    14.         // Get the Steam Lobby ID.
    15.         lobbyID = (CSteamID)callback.m_ulSteamIDLobby;
    16.      
    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());
    20.  
    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. }
    26.  
    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):
    1.  
    2. private void RecallAndPrintLobbyDataEntry(){
    3.        
    4.         string temp2 = SteamMatchmaking.GetLobbyData(lobbyID, "captain");
    5.         print($"The Captain's Steam ID is: {temp2}");
    6. }
    7.  
    OUTPUT: The Captain's Steam ID is: <--- Nada! Zero! Zip! Nuthin! grrrrrr. 8( Same code!
     
    Last edited: Oct 14, 2021
  2. Please hit the Edit link on your post and put your code in code tags like it is described here: https://forum.unity.com/threads/using-code-tags-properly.134625/

    It is unreadable otherwise.

    --
    I suspect you are calling this
    RecallAndPrintLobbyDataEntry
    method before the
    OnSteamLobbyCreated
    running so you don't have a
    lobbyID
    set?
     
  3. Kinnith7

    Kinnith7

    Joined:
    Jul 4, 2017
    Posts:
    84
    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

    Kinnith7

    Joined:
    Jul 4, 2017
    Posts:
    84
    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

    BlackstarWarrior

    Joined:
    Sep 8, 2021
    Posts:
    1
    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

    Kinnith7

    Joined:
    Jul 4, 2017
    Posts:
    84
    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

    GaborL

    Joined:
    Oct 31, 2015
    Posts:
    6
    If you call SteamMatchmaking.RequestLobbyData before JoinLobby, the data will be available in LobbyEntered callback.
    upload_2022-10-4_23-37-14.png
     
  8. Reimirno7

    Reimirno7

    Joined:
    Nov 25, 2021
    Posts:
    51
    I think the problem is that the `LobbyEnter_t.m_ulSteamIDLobby` client gets is the host's steam id, not the actual lobby id (the `LobbyEnter_t.m_ulSteamIDLobby` host gets is the actualy lobby id). So `GetLobbyData, GetLobbyOwner` won't even work on client since you are not having the right id. You can try console log the ids you get and see.

    I am not sure how to deal with this either.

    I don't think this works? RequestLobbyData won't add any info to LobbyEnter_t you receive.
     
  9. PrivateStakes

    PrivateStakes

    Joined:
    Mar 7, 2019
    Posts:
    1

    Just checking in if the issue was resolved. I've hit the same wall with the GetLobbyData returning "", and I'm just poking around for a solution. Tried the solution proposed by Remirino7, to use LobbyEnter_t.m_ulSteamIDLobby directly, but the ulong returned cannot be used to connect to the steam host I've set up. Tried using the RequestLobbyData method call as well prior and it doesn't return false, so I'm quite puzzled.
     
  10. Kinnith7

    Kinnith7

    Joined:
    Jul 4, 2017
    Posts:
    84
    @PrivateStakes Hi, sorry for the delay in my reply, I have been working a lot. It's been a while since I figured it out but, and I can't remember if I am saying this correctly, but the return string from the steam lobby had a "null character" at the end (or beginning) that had to be truncated, or it would just cut off the entire rest of the string. It was weird. At least to me cause I'm still a bit of a noob. I just went back and tried to find the code that I used to fix it but couldn't. Sorry. But I am sure that was the problem. There is some type of null character on your string that is chopping off everything after it. Hope this at least points you in the right direction.
     
  11. Kinnith7

    Kinnith7

    Joined:
    Jul 4, 2017
    Posts:
    84
    @PrivateStakes Here is something. It's a \0 that needs to be deleted in your string.

    "A null character (\0) with ASCII value 0 is a special character used to terminate char-array strings in C/C++, that is, to keep track of where they end. This is used, for instance, to calculate the length of the string."