Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Question Need some help properly setting up Steam login

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

  1. CallMePasc

    CallMePasc

    Joined:
    Oct 17, 2022
    Posts:
    4
    I tried to follow the Steam login docs:
    https://docs.unity.com/ugs/en-us/manual/authentication/manual/platform-signin-steam

    I installed the SDK using this: https://steamworks.github.io/installation/
    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;
    4.  
    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);
    15.  
    16.     m_AuthTicket = SteamUser.GetAuthTicketForWebApi("unityauthenticationservice");
    17. }
    18.  
    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

    erickb_unity

    Unity Technologies

    Joined:
    Sep 1, 2021
    Posts:
    103
    Hello

    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.
    (AuthenticationService.Instance.SignInWithSteamAsync)

    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.
     
    Bunny83 likes this.
  3. khangng2001

    khangng2001

    Joined:
    Jun 11, 2020
    Posts:
    1
    Hi there, to use the login game with Steam feature, do I have to become Steam partner cause it requires 100$ for depositing