In an ItemInstance, where can I find the tag(s) in C# with Unity?
(Sorry about so many posts recently haha I've been on a PF rampage!)
EDIT: Forgot img
In an ItemInstance, where can I find the tag(s) in C# with Unity?
(Sorry about so many posts recently haha I've been on a PF rampage!)
EDIT: Forgot img
The problem your having is that you are trying to access a CatalogItem property with a ItemInstance object.
So long story short to get the tags for a ItemInstance you must search through your catalog of items for the matching item. ItemInstance.ItemId == CatalogItem.ItemId. From there you can use CatalogItem object and get the tags by doing CatalogItem.Tags.
Please see this post for more info on the topic of mapping ItemInstance objects to CatalogItem objects.
This is the answer - cheers! ..But it (the API/SDK) is definitely not intuitive if this is still the main way to do it. To save time, a lazy workaround would be to store tags in annotation and just split() with commas. Would also save processing if you don't have to iterate.
This really needs to be changed or everyone will have different ways of doing the core functions instead of having a standard like most other calls
EDIT: Added feat req https://community.playfab.com/idea/5738/make-items-more-intuitive-in-terms-of-accessing-ce.html
EDIT 2: @Joshua Strunk I just saw your comment - I think I see what you're saying - I'll try it out.
In this situation I always recommend when you pull a catalog from PlayFab just instantly build a dictionary. Dictionary<string, CatalogItem> catalog. This is instead of storing it as returned by the API as a List<CatalogItem>. You can still iterate through all the items in dictionary if needed and this allows you to quickly map ItemInstances to CatalogItems by doing catalog[itemInstance.ItemId].
Oh, actually, I'm getting the items from loginResult.InfoResultPayload.UserInventory so I don't actually have access to the catalog unless I call it separately. But using payload is kind of the reason to not call it separately in the first place to have it all at once, or the point is lost.
I'm still newish at PF so maybe there's another way, but I'm out of ideas.
EDIT: So I'm still not sure about the correct way to do this -- the answer seems that I actually need to make a 2nd call to GetCatalogItems - is this correct? Meaning, I can't resolve this by only the LoginResult type (via the info result payload.userinventory)?
EDIT 3: I suppose most catalogs won't change during a game session .. maybe I'm going about this wrong. Instead of grabbing it each time, should I grab it at the very beginning of the game and no need to check again? Maybe as soon as a successful semi-anon device ID login (same time I grab the news)?
// Save in dictionary for more convenient references to find item info catalogDict = new Dictionary<string, CatalogItem>(); foreach (CatalogItem item in catalog.Catalog) { catalogDict.Add(item.ItemId, item); }
Something like this?
Woot I got it! Thanks! After putting into dictionary:
List<string> tags = catalogDict[item.ItemId].Tags;
2 People are following this question.