Search Unity

Initializing/restoring many purchases on Google Play freezes game

Discussion in 'Unity IAP' started by TMK, Sep 6, 2021.

  1. TMK

    TMK

    Joined:
    Mar 29, 2010
    Posts:
    91
    Hey!

    I have a game that has over 250 non-consumable IAP's on the Google Play Store. I've been using Unity IAP 1.20.1 but updated to the newest 4.0.3 now in order to prepare for the new Google billing API requirement that goes live in November.

    The issue is, the more non-consumable purchases a player has the longer it takes for Unity IAP 4.0.3 to finish initialize/restore purchases. So if a player has bought e.g. 150 non-consumable IAP's, it takes over 1 minute for Unity IAP's code to finish initializing, on every restart of the game. So it freezes the game for 1 minute.

    On logcat, it goes through every purchase with "Unity IAP: Already recorded transaction ..." logs, and each log takes about 1 second.

    This didn't happen in 1.20.1 of Unity IAP but is happening in 4.0.3. In 1.20.1 it restored all 150+ purchases without any kind of freezing.

    Is there anything that can be done to fix this? Thanks!

    In order to test this:

    Have a project with e.g. 100 non-consumable IAP's. Test purchase as many as you can, and the more you buy, the slower it will take for Unity IAP to initialize and restore them on every app restart.

    Project version details:

    Unity 2020.3.17f1 LTS
    Unity IAP 4.0.3
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    We are looking into removing that log message in a future release. Does initializing with 1/2 the product cut the initialization time in 1/2, for example? We have not heard of this issue. That is an unusual number of IAP products, have you considered using FetchAddtionalProducts?
     
  3. TMK

    TMK

    Joined:
    Mar 29, 2010
    Posts:
    91
    Yes, initializing with 1/2 products cuts the time in 1/2 too.

    I tried using "IStoreController.FetchAdditionalProducts" instead now, initializing all of the products using that instead, and it uses the same amount of time to initialize them unfortunately.
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes, you would not use FetchAdditionalProducts during initialization, but later in the game most likely. Do you really need 250 products to initialize your game? Can you not customize the product list once the user has logged in, for example, and perhaps has some history?
     
  5. TMK

    TMK

    Joined:
    Mar 29, 2010
    Posts:
    91
    Oh, yeah, I can try to implement it that way instead, using FetchAdditionalProducts whenever the player opens a pack, and restore the purchase. That should work as an alternative solution hopefully.

    Since it worked fine in 1.20.1 to initialize/restore all 250 in one go, I hoped there was a way to make it work in 4.0.3 too. I can let you know if there are any issues with it. Thanks!
     
  6. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Restore the purchase? Can you clarify? Restore happens automatically on Google, and Apple requires a Restore button.
     
  7. TMK

    TMK

    Joined:
    Mar 29, 2010
    Posts:
    91
    This whole 1 minute freezing app problem is due to Google automatically restoring the 150 test purchases I mentioned, when initializing the Unity IAP SDK.

    The more purchases a player has, the longer it takes for the game to start up when it's using Unity IAP 4.0.3 since Google restores them automatically on every restart.

    However, in Unity IAP 1.20.1 there was no 1 minute freeze, it restored all purchases without any kind of freezing. So there's something different in 4.0.3 with regards to how long it takes to restore a purchase compared to 1.20.1.
     
  8. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Got it, test purchases and not actual users. 4.0.3 uses Google Billing Library v3 compared to 1.20.1
     
  9. TMK

    TMK

    Joined:
    Mar 29, 2010
    Posts:
    91
    It also happens for real users, just easier to test using test purchases.
     
  10. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    But the issue isn't IAP initialization with many products, that should be fast. It's with the Restore process, where multiple ProcessPurchase calls are made. That is, a new user would not see this issue, correct? What are you doing in ProcessPurchase?
     
  11. TMK

    TMK

    Joined:
    Mar 29, 2010
    Posts:
    91
    Correct, like I mentioned in the original post, the issue is restoring many purchases. The more purchases you have, the longer it takes for the restore process (which is started automatically in the initialization phase), which freezes the game.

    It doesn't have anything to do with the amount of IAP's, it's the amount of restored purchases.

    I don't do anything special in ProcessPurchase, it happens even if I comment out all the code there. It's the Unity IAP internal code that causes the freezing.
     
  12. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Sorry for the confusion. I had meant earlier (and asked specifically previously), does this happen for new users AND with initializing with all products? But in summary, your claim is that the ProcessPurchase callback rate isn't what it used to be. We really don't have any control over that, we are calling the Google Billing Library v3 API now.
     
  13. TMK

    TMK

    Joined:
    Mar 29, 2010
    Posts:
    91
    I just tried the newest version of Prime31's IAP plugin, which also uses Google Billing Library v3 API. It works perfectly fine, it restores all 150+ purchases under 1 sec, while Unity IAP uses 1 minute.

    I tested them both in new clean projects as well. So there is something extra that Unity IAP does that makes it freeze on every purchase it restores.

    If you feel like there's nothing you can do, I will try to work around it, or implement Prime31 instead (but I'd like to avoid that as I don't want 2 different IAP plugins in 1 project).
     
  14. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Just to confirm, Unity IAP is fast to initialize for 150 products for a new user that hasn't made any previous purchases? You still haven't stated yet. It is ONLY the restore process that is taking the time? Please confirm. You are likely correct, but this information would be important.
     
  15. TMK

    TMK

    Joined:
    Mar 29, 2010
    Posts:
    91
    Correct, for new users it is very fast to initialize. It is only the restore purchases process that the issue is with. The more purchases the user has, the longer it takes to restore. Thanks!