question

oriel avatar image
oriel asked

HOW DO I GET INVENTORY IN UNITY

I SERIOUSLY CANNOT FIND ANY TUTORIAL ANYWHERE THAT IS CLEAR ON HOW TO USE IT,I SERIOUSLY CANNOT FIND ANY TUTORIAL ANYWHERE

Player Inventory
10 |1200

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

Neils Shi avatar image
Neils Shi answered

You can refer to my testing example code, It will print out the item ID from the currently logged in player's inventory.

 void Start()
     {
         var request = new LoginWithPlayFabRequest { Username = "", Password = "" };
         PlayFabClientAPI.LoginWithPlayFab(request, OnLoginSuccess, OnLoginFailure);
     }
    
     private void OnLoginSuccess(LoginResult result)
     {
         Debug.Log("login successful!");
         TestGetUserInventory();
     }
     public void TestGetUserInventory()
     {
         PlayFabClientAPI.GetUserInventory(new PlayFab.ClientModels.GetUserInventoryRequest()
         {
    
         },
         result => { 
             Debug.Log("Get User Inventory successful");
             foreach (var item in result.Inventory)
             {
                 Debug.Log("Item: " + item.ItemId);
             }
         },
         error => {
             Debug.Log("Got error getting user Inventory");
             Debug.Log(error.GenerateErrorReport());
         });
     }
    
     private void OnLoginFailure(PlayFabError error)
     {
         Debug.LogWarning("Something went wrong with login API call.  :(");
         Debug.LogError(error.GenerateErrorReport());
     }
10 |1200

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

Neils Shi avatar image
Neils Shi answered

Could you tell us which economy you are using? Legacy Economy or Economy v2? In Legacy Economy, you can call API GetUserInventory to retrieve the specified user's current inventory of virtual goods. For more info, you can refer to Economy (Legacy) quickstart - PlayFab | Microsoft Learn. In Economy v2, you can retrieve player’s inventory via API GetInventoryItems. For more details, please refer to Player Inventory Quickstart - PlayFab | Microsoft Learn.

1 comment
10 |1200

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

oriel avatar image oriel commented ·

legacy i know that its getuserinventory but idk how to use it

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.