Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

Help Wanted How to edit store items runtime?

Discussion in 'Game Foundation' started by zhukovv, May 14, 2020.

  1. zhukovv

    zhukovv

    Joined:
    Nov 4, 2019
    Posts:
    16
    Hello,

    first of all, thank you for such a great tool!

    I need two store views - one acts as a shop with purchasable items, and the other as an inventory, which displays those items after purchase. I thought I could use two store instances for this purpose, and just hide a purchased item in one of them, and show in the other, for example.
    I thought of accessing and modifying a transaction item after purchase or change the visibility of the item in the list of store items but could find how to do it runtime, not in Editor.

    Any help would be really appreciated, thank you in advance!
     
  2. erika_d

    erika_d

    Unity Technologies

    Joined:
    Jan 20, 2016
    Posts:
    400
    Hi @zhukovv

    Glad you're enjoying it so far!

    We don't currently have a way to make items invisible or remove them from the store at runtime based on in game actions. It's an idea we've played with though in the past, so I'll add your use case of hiding once purchased to the notes for the feature request.

    I do have some questions about what you're trying to achieve and why you're going about it this way though.

    1) Are these non-consumable items or consumable? (Currently our store doesn't really support non-consumable)

    2) Why are you choosing to use a store to represent an inventory of purchased items? Is it cause you want them to be re-purchasable from that location (like a purchase history type thing)? Or are you simply wanting an inventory that shows them what items they have? If the former, that's an interesting use case that I personally haven't heard discussed yet. For the latter though I would propose using the inventory system to display what items they own. If the rewards section of a transaction is configured, the Transaction system will automatically add whatever items added there to the Game Foundation Inventory Manager when purchased. You could then display all items in the Inventory Manager to show what items they have. (This doesn't address the hiding them in the store part of the question though)

    Answers to those questions and any other information you can give about your use case would help us to guide the best way to achieve it!
     
    zhukovv and mingz-unity like this.
  3. zhukovv

    zhukovv

    Joined:
    Nov 4, 2019
    Posts:
    16
    Hi Erika,

    thank you for your answer!

    1) Inventory items - I guess non-consumable, we have an AR game and use them to show which 3D models a user has, and clicking on an item shows the corresponding model in the AR scene. Before we had just a set of free items, and using Store View for this scenario was just fine, but now we also need to add items which user can purchase with a soft currency to expand the inventory.

    2) Yes, I just want an inventory that shows what items users have) And I thought that Store View is very handy for such purpose - with the grid, clickable items with icons, name, etc)
    I was thinking of creating another script based on StoreView.cs to display the Inventory Manager items, but yes - it still leaves a question of how to prevent repeated purchases in the store. And also how to initially populate the inventory with the free items)
     
    erika_d likes this.
  4. erika_d

    erika_d

    Unity Technologies

    Joined:
    Jan 20, 2016
    Posts:
    400
    Thanks for the additional info, @zhukovv!

    Have you checked out the Transaction Item prefab? The Store View auto populates with Transaction Items, but you can manually create transaction items as well. (Check out the Store sample, List Store - Portrait/Landscape - Manual scenes to see how to do that.) I think that would be your best bet for being able to choose which transactions in a store to show. You can write your own Store View (either using ours as a template or starting fresh) that keeps track of which items have been purchased and destroys (or disables) the Transaction Item prefabs for the ones that have been purchased.

    And then use the Inventory Manager to show the items that they have, (you can check whether the inventory already has the free items in it and if not manually instantiate them). Also check out the Inventory Item View prefab, if you haven't already. It shows an icon for an inventory item and a quantity, but you could tweak it to show name instead of quantity which probably fits your needs better. And then tweak the StoreView to show those Inventory Item prefabs, as you suggest.

    The feature needs that I'm seeing here are
    1) support for non-consumables
    2) Inventory View prefab like Store View prefab
    3) Maybe some different styles of Inventory Item prefabs
    4) Auto initialization of certain Inventory Items in the Inventory

    These are all things that are on our desires list as well, although I have no idea if or when they'll get put on our roadmap. But hopefully the existing prefabs will be a helpful enough starting point for you that you can get it working, and stay tuned for future releases! Let us know if these ideas will work as a workaround for you. :)
     
    zhukovv likes this.
  5. zhukovv

    zhukovv

    Joined:
    Nov 4, 2019
    Posts:
    16
    Hi Erika!

    I tried the Transaction Item prefab, thank you, that's a good option!

    Yes, your suggestions will work as a workaround, we will use them for now, thank you very much and looking forward to the future Game Foundation updates!)
     
    erika_d likes this.
  6. ItzChris92

    ItzChris92

    Joined:
    Apr 26, 2017
    Posts:
    371
    Hello, I just came across this thread and wanted to ask what was meant by store's not being meant for non-consumables?
     
  7. erika_d

    erika_d

    Unity Technologies

    Joined:
    Jan 20, 2016
    Posts:
    400
    Hi @ItzChris92

    At the time of that post our store prefab and transaction system didn't support non-consumables very well (i.e. the idea that an in app purchase can only be purchased once and is then owned forever). Our most recent release (early July) however did add non-consumable support to the transaction system and store prefabs. Hope that helps!
     
    ItzChris92 likes this.
  8. geg8285

    geg8285

    Joined:
    Sep 30, 2015
    Posts:
    6
    Hi @Erika and all users of GF,

    I have some additional info related to this topic:

    #1. It will be very helpful if you add the non-consumable/consumable/subscription mechanism for VirtualTransaction as it implemented in IAP transactions. I did a workaround by adding a static property called "PurchaseType" with possible values "non-consumable/consumable/subscription" and filter this property on StoreView before displaying the transaction - the same as it implemented for IAPTransaction. (like this method "bool IsIAPTransactionPurchasable(IAPTransaction iapTransaction")). But after reopening Unity all my code, that was added to StoreView.cs have disappeared - I fixed it with the solution described in this thread https://forum.unity.com/threads/putting-out-an-item-after-buying-from-store.932874/
    - copying StoreView.cs and related scripts to my project and modifying them there.

    #2. I have found some bug that was mentioned in some thread before:
    If the balance in the wallet too low and I increase it - the virtual transactions stay not purchasable till the next session. (need workaround in StoreView.cs - calling UpdateContent).
    Also, if you fix the issue #1 - so you need to call UpdateContent like here -

    "if (transaction is IAPTransaction iapTransaction && iapTransaction.product.definition.type == ProductType.NonConsumable)
    {
    UpdateContent();
    }"

    as well.

    Thank you!
     
    Last edited: Sep 28, 2020
  9. erika_d

    erika_d

    Unity Technologies

    Joined:
    Jan 20, 2016
    Posts:
    400
    Hi @geg8285,

    Thank you for your feedback on the IAP transactions. To make sure I understand what you're asking, you would like there to be an additional field on Game Foundation's IAPTransaction where you can specify Consumable/Non-Consumable/Subscription, so you don't have to access it via iapTransaction.product.definition.type?
    Or is it the filtering ability that is more important to you, and you'd like a more built in way to specify filtering based on what's in iapTransaction.product.definition.type?

    Your workaround for this sounds like it totally works, I may suggest adding the info as a Tag instead of a Property though. We already have built in filtering by Tags built into StoreView, so you shouldn't need to edit/duplicate StoreView if you want to do it that way.

    (Also I'll note for the record that currently GameFoundation doesn't support subscription IAPs.)

    For number #2, thank you for the bug report, it is on our list to fix!

    But for this part, I'm not exactly sure what you mean. Are you saying that when non consumable items are purchased the transaction item for that purchased item doesn't get hidden in the StoreView? Or something else?
     
unityunity