question

Dylan Hunt avatar image
Dylan Hunt asked

How to find item tag in C# (Unity)?

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

apis
where-tag.png (7.5 KiB)
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

·
Joshua Strunk avatar image
Joshua Strunk answered

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.

5 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.

Dylan Hunt avatar image Dylan Hunt commented ·

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.

1 Like 1 ·
Joshua Strunk avatar image Joshua Strunk commented ·

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].

0 Likes 0 ·
Show more comments

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.