Search Unity

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

Question Need some help properly setting up Steam login

Discussion in 'Scripting' started by CallMePasc, Nov 25, 2023.

  1. CallMePasc


    Oct 17, 2022
    I tried to follow the Steam login docs:

    I installed the SDK using this:
    I tried Option B first since that seemed easiest, but it didn't seem to work.
    So I went with Option A and that worked.

    Then I tried to implement the code snippets, but they were very confusing.
    It doesn't explain what anything is, where to put it, or how to use it.

    After struggling for about 3 hours I finally got it to work, but I'm not sure if I did everything properly.

    Here's the first code snippet from the docs page:

    Code (CSharp):
    1. Callback<GetTicketForWebApiResponse_t> m_AuthTicketForWebApiResponseCallback;
    2. HAuthTicket m_AuthTicket;
    3. string m_SessionTicket;
    5. void SignInWithSteam()
    6. {
    7.     // It's not necessary to add event handlers if they are
    8.     // already hooked up.
    9.     // Callback.Create return value must be assigned to a
    10.     // member variable to prevent the GC from cleaning it up.
    11.     // Create the callback to receive events when the session ticket
    12.     // is ready to use in the web API.
    13.     // See GetAuthSessionTicket document for details.
    14.     m_AuthTicketForWebApiResponseCallback = Callback<GetTicketForWebApiResponse_t>.Create(OnAuthCallback);
    16.     m_AuthTicket = SteamUser.GetAuthTicketForWebApi("unityauthenticationservice");
    17. }
    19. void OnAuthCallback(GetTicketForWebApiResponse_t callback)
    20. {
    21.     var Token = BitConverter.ToString(callback.m_rgubTicket).Replace("-", string.Empty);
    22.     m_AuthTicketResponseCallback.Dispose();
    23.     m_AuthTicketResponseCallback = null;
    24.     Debug.Log("Steam Login success. Session Ticket: " + m_SessionTicket);
    25.     // Call Unity Authentication SDK to sign in or link with Steam.
    26. }
    The variable at the top is named m_AuthTicketForWebApiResponseCallback but then in the code itself there's suddenly a variable m_AuthTicketResponseCallback that doesn't exist. Is this just a typo?

    m_SessionTicket is never set and not used except for in the Debug.Log
    I assume this is supposed to be Token?

    Then the next two code snippets don't explain anything.
    When/where do you call them? In what order? Why?

    The identity variable was a huge mystery too, but eventually I figured out it's the same as in the first code snippet "unityauthenticationservice" - I think?

    There's no links to further explanations or documentation anywhere.

    So my main questions:

    1) Do I need to do these? On which variable?
    Code (CSharp):
    1. m_AuthTicketResponseCallback.Dispose();
    2. m_AuthTicketResponseCallback = null;
    2) Am I correct that the identity = "unityauthenticationservice"

    3) What is the var Token for?

    4) What is HAuthTicket m_AuthTicket; for? It's assigned a value, but never used.

    5) What is string m_SessionTicket; for? It's never set nor used.
    Last edited: Nov 25, 2023
  2. erickb_unity


    Unity Technologies

    Sep 1, 2021

    1) It's a good practice to reset and dispose of the resource after using it

    2) The identity value is up to you. It just needs to match what you send in the GetAuthTicketForWebApi & SignInWithSteamAsync.

    3) The Token is what you send to the SignInWithSteam from the Authentication service.

    4) HAuthTicket has no use beyond holding the value in a local variable in this sample.

    5) I think the Token was meant to be assigned to m_SessionTicket.

    I'll raise it to the team that the docs needs to be fixed.
    I hope this help.