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 Initializing Player Data when a new account is created

Discussion in 'Unity Gaming Services General Discussion' started by bytebytebytebyte, Aug 9, 2023.

  1. bytebytebytebyte

    bytebytebytebyte

    Joined:
    Dec 5, 2017
    Posts:
    14
    What's the recommended way of initializing Player Data when a new account is created? Let's say Energy = 30, Gold = 0, etc. How can I achieve this using UGS?
     
  2. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    355
    What kind of player data? The things you mentioned could be economy elements, meaning those can have a default value set that you then can use.
     
  3. bytebytebytebyte

    bytebytebytebyte

    Joined:
    Dec 5, 2017
    Posts:
    14
    Yes, that's what I need, but I have another question. I've set up the Economy and authentication. However, after the first login, the 'Currencies' tab displays the message 'No Currency Balances'. Why isn't the Initial balance of 30, which I configured, showing up in the 'Currencies' tab for the player? Do I need to call any additional methods?

    Code (CSharp):
    1. await AuthenticationService.Instance.SignInAnonymouslyAsync();
    2. await EconomyService.Instance.Configuration.SyncConfigurationAsync();
    3.  
    4. public void FetchCurrencies()
    5.         {
    6.             if (!IsInitialized)
    7.             {
    8.                 return;
    9.             }
    10.            
    11.             List<CurrencyDefinition> currencies = EconomyService.Instance.Configuration.GetCurrencies();
    12.  
    13.             if (currencies.Count == 0)
    14.             {
    15.                 Debug.Log("No currencies");
    16.             }
    17.             else
    18.             {
    19.                 foreach (var currency in currencies)
    20.                 {
    21.                     Debug.Log($"ID: {currency.Id}, Name: {currency.Name}, Max Allowed: {currency.Max}, Initial Value: {currency.Initial}\n");
    22.                 }
    23.                
    24.             }
    25.         }