question

edogn12 avatar image
edogn12 asked

How do I use the GetUserInventory function to find an ItemInstanceId?

	void GetInventory() {
		PlayFabClientAPI.GetUserInventory(new GetUserInventoryRequest(), LogSuccess, LogFailure);
	}
In-Game Economy
10 |1200

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

Andy avatar image
Andy answered

Each item's itemInstanceId is returned as part of the collection of ItemInstances in the Inventory property of the GetUserInventory response (https://api.playfab.com/documentation/client/method/GetUserInventory).

It's not the clearest example, but you can see how it can be done here:

https://github.com/PlayFab/UnicornBattle/blob/master/UnicornBattle/Assets/Scripts/PF_StaticsAndHelpers/PF_PlayerData.cs#L78

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.

edogn12 avatar image edogn12 commented ·

Trying to use the example code from the unicorn battle for only the stuff I need, I came up with this but it gives me an error saying "No overload for for method 'GetUserInventory' takes two arguments". I am new to this kind of stuff so any help is appreciated.

public void GetUserInventory() {
		PlayFabClientAPI.GetUserInventory(new GetUserInventoryRequest(),(GetUserInventoryResult result) =>
			{
				
		playerInventory.Clear();
		foreach (var eachItem in result.Inventory)
		playerInventory.Add(eachItem);
		Debug.Log(playerInventory);


			});
	}
0 Likes 0 ·
edogn12 avatar image
edogn12 answered

For anybody else who is having trouble, I used this code to search the inventory to find instance Id:

	public void GetInventory() 
	{
		PlayFabClientAPI.GetUserInventory(new GetUserInventoryRequest(),OnGetInventory,error => Debug.LogError(error.GenerateErrorReport()));
	}




	public void OnGetInventory(GetUserInventoryResult result)
	{
		Debug.Log("Received the following items:");
		foreach (var eachItem in result.Inventory)
			Debug.Log("Items (" + eachItem.DisplayName + "): " + eachItem.ItemInstanceId);
	}
10 |1200

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

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.