question

James N avatar image
James N asked

Unity Serialization (beginner question) - no virtual currencies

Hi Everyone,

No doubt this question is about my own inexperience with Playfab, Unity and game development. I'm building a game as a learning experience and I've been doing a bunch of tutorials on how to get Playfab working. Unfortunately most of the YouTube tutorials from Playfab themselves are out of date. I guess that happens when you're a small company trying to improve the core product for experienced devs ;)

The most accessible tutorial I've found so far is on YouTube by a user called zSkeeter135. In short, he takes us through setting up playfab in a Unity game and working with the SDK. Exactly the kind of content that I need. Everything was going quite well until about 32:58 into this video - https://www.youtube.com/watch?v=1o51D_yOhHs

When zSkeeter takes us through the serialized fields coming from the account info class we made in an earlier episode, he shows the fields in the Unity Inspector - including Player Virtual Currency.

The class we created in the earlier video seems reasonably straight forward - it goes off to the Playfab.Clientmodles namespace and returns GetPlayerCombinedInfoResultPayload as a serializable field:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using PlayFab;

using PlayFab.ClientModels;



public class AccountInfo : MonoBehaviour {





    private static AccountInfo instance;



    public static AccountInfo Instance 

    {



        get { return instance; }

        set { instance = value; }

    }




/// this bit here is what goes off to the PlayFab SDK for the player info
    [SerializeField]

    private GetPlayerCombinedInfoResultPayload info; 



    public GetPlayerCombinedInfoResultPayload Info 

    {

        get { return info; }

        set { info = value; }



    }





    private void Awake() {



        if(instance != this)

            instance = this;

        DontDestroyOnLoad(gameObject);



    }



    public static void Register(string username, string email, string password){

        //used to register a new playfab account

        RegisterPlayFabUserRequest request = new RegisterPlayFabUserRequest()

        {

            //request

            TitleId = PlayFabSettings.TitleId,

            Email = email,

            Username = username,

            Password = password,

            //DisplayName = 



        };



        PlayFabClientAPI.RegisterPlayFabUser(request, OnRegister, GameFunctions.OnAPIError);



    }



    static void OnRegister(RegisterPlayFabUserResult result){



        Debug.Log("Registered with: " + result.PlayFabId);



    }





    public static void Login(string username, string password){

        //used to register a new playfab account

        LoginWithPlayFabRequest request = new LoginWithPlayFabRequest()

        {

            //request

            TitleId = PlayFabSettings.TitleId,

            Username = username,

            Password = password,

            //DisplayName = 



        };



        PlayFabClientAPI.LoginWithPlayFab(request, OnLogin, GameFunctions.OnAPIError);



    }



    static void OnLogin(LoginResult result){



        Debug.Log("Login with: " + result.PlayFabId);



    }






//this Function here populates these fields 
    public static void GetAccountInfo(string playFabId){



        GetPlayerCombinedInfoRequestParams paramInfo = new GetPlayerCombinedInfoRequestParams()

        {

            GetTitleData = true,

            GetUserInventory = true,

            GetUserAccountInfo = true,

            GetUserVirtualCurrency = true,

            GetPlayerProfile = true,

            GetPlayerStatistics = true,

            GetUserData = true,

            GetUserReadOnlyData = true

        };



        

        GetPlayerCombinedInfoRequest request = new GetPlayerCombinedInfoRequest()

        {

            PlayFabId = playFabId,

            InfoRequestParameters = paramInfo

        };



        PlayFabClientAPI.GetPlayerCombinedInfo(request, OnGotAccountInfo ,GameFunctions.OnAPIError);



    }



    static void OnGotAccountInfo(GetPlayerCombinedInfoResult result){



        Debug.Log("Updated account info");

        Instance.Info = result.InfoResultPayload;



    }

}

When I look at the Playfab SDK, at line 1957 of PlayFabClientModels.cs, I see all the fields that do get serialized into the Unity inspector:

    [Serializable]

    public class GetPlayerCombinedInfoResultPayload

    {

           /// <summary>

        /// Account information for the user. This is always retrieved.

        /// </summary>

        public UserAccountInfo AccountInfo;

        /// <summary>

        /// Inventories for each character for the user.

        /// </summary>

        public List<CharacterInventory> CharacterInventories;

        /// <summary>

        /// List of characters for the user.

        /// </summary>

        public List<CharacterResult> CharacterList;

        /// <summary>

        /// The profile of the players. This profile is not guaranteed to be up-to-date. For a new player, this profile will not

        /// exist.

        /// </summary>

        public PlayerProfileModel PlayerProfile;

        /// <summary>

        /// List of statistics for this player.

        /// </summary>

        public List<StatisticValue> PlayerStatistics;

        /// <summary>

        /// Title data for this title.

        /// </summary>

        public Dictionary<string,string> TitleData;

        /// <summary>

        /// User specific custom data.

        /// </summary>

        public Dictionary<string,UserDataRecord> UserData;

        /// <summary>

        /// The version of the UserData that was returned.

        /// </summary>

        public uint UserDataVersion;

        /// <summary>

        /// Array of inventory items in the user's current inventory.

        /// </summary>

        public List<ItemInstance> UserInventory;

        /// <summary>

        /// User specific read-only data.

        /// </summary>

        public Dictionary<string,UserDataRecord> UserReadOnlyData;

        /// <summary>

        /// The version of the Read-Only UserData that was returned.

        /// </summary>

        public uint UserReadOnlyDataVersion;

        /// <summary>

        /// Dictionary of virtual currency balance(s) belonging to the user.

        /// </summary>

        public Dictionary<string,int> UserVirtualCurrency;

        /// <summary>

        /// Dictionary of remaining times and timestamps for virtual currencies.

        /// </summary>

        public Dictionary<string,VirtualCurrencyRechargeTime> UserVirtualCurrencyRechargeTimes;





    }

And, everything here seems to serialize all the way down to "user Read Only Data Version", but the virtual currencies and virtual currency recharge times don't show up in the inspector - even if I rearrange this class.

In the video, virtual currency appears under "player profile" - as you can see from the screenshot of the Unity Inspector, they don't appear there now.

So - to the meat and potatoes of this post - what is it that I'm doing wrong/not understanding? :-)

Player Data
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
pfnathan avatar image
pfnathan answered

Can you run it thorough Postman and let us know what your result is?

https://api.playfab.com/blog/executing-playfab-api-via-postman

4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

James N avatar image James N commented ·

Thanks for your quick reply @pfnathan - I don't think it's a problem with executing the APIs because the properties should appear in Unity's inspector when it compiles the class. These properties should appear when I add the script component to the empty game-object. The properties that do appear are populated when I run the game.

Is it possible that the virtual currencies properties have been moved into a different class that isn't being serialized?

0 Likes 0 ·
pfnathan avatar image pfnathan ♦ commented ·

Can you let us know your Title ID please, would like to investigate bit deeper.

0 Likes 0 ·
James N avatar image James N commented ·

@pfnathan title ID is 351, using the most recent SDK installed via the Unity developer extension :-)

0 Likes 0 ·
pfnathan avatar image pfnathan ♦ commented ·

You are correct that “VirtualCurrencyBalances” is not visible on the Unity Inspector field.

No "VirtualCurrencyBalances" is supported on PlayerProfileModel at this point but it will be supported in a future release.

https://api.playfab.com/documentation/Client/datatype/PlayFab.Client.Models/PlayFab.Client.Models.PlayerProfileModel

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.