Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

IAP 2.2.0 Error after purchase

Discussion in 'Unity IAP' started by michaeltepl, Nov 11, 2020.

  1. michaeltepl

    michaeltepl

    Joined:
    Dec 26, 2013
    Posts:
    22
    Hi! Yesterday I updated IAP plugin to the latest version and now I am getting next error:

    UnityException: Transaction can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
     

    Attached Files:

  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
  3. michaeltepl

    michaeltepl

    Joined:
    Dec 26, 2013
    Posts:
    22
    Here is my code. It works fine with IAP version 2.1.1

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Purchasing;
    3.  
    4. public class MyIAPManager : MonoBehaviour, IStoreListener {
    5.  
    6.     private IStoreController controller;
    7.     private IExtensionProvider extensions;
    8.  
    9.     public void Start () {
    10.         var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    11.         builder.AddProduct("coins_099", ProductType.Consumable);
    12.         UnityPurchasing.Initialize (this, builder);
    13.     }
    14.  
    15.     /// <summary>
    16.     /// Called when Unity IAP is ready to make purchases.
    17.     /// </summary>
    18.     public void OnInitialized (IStoreController controller, IExtensionProvider extensions)
    19.     {
    20.         this.controller = controller;
    21.         this.extensions = extensions;
    22.         controller.InitiatePurchase("coins_099");
    23.     }
    24.  
    25.     /// <summary>
    26.     /// Called when Unity IAP encounters an unrecoverable initialization error.
    27.     ///
    28.     /// Note that this will not be called if Internet is unavailable; Unity IAP
    29.     /// will attempt initialization until it becomes available.
    30.     /// </summary>
    31.     public void OnInitializeFailed (InitializationFailureReason error)
    32.     {
    33.     }
    34.  
    35.     /// <summary>
    36.     /// Called when a purchase completes.
    37.     ///
    38.     /// May be called at any time after OnInitialized().
    39.     /// </summary>
    40.     public PurchaseProcessingResult ProcessPurchase (PurchaseEventArgs e)
    41.     {
    42.         return PurchaseProcessingResult.Complete;
    43.     }
    44.  
    45.     /// <summary>
    46.     /// Called when a purchase fails.
    47.     /// </summary>
    48.     public void OnPurchaseFailed (Product i, PurchaseFailureReason p)
    49.     {
    50.     }
    51. }
     
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    You are automatically doing a purchase each time during initialization? That is not correct. Please remove that line and test again.
     
  5. michaeltepl

    michaeltepl

    Joined:
    Dec 26, 2013
    Posts:
    22
    Same behavior when I call controller.InitiatePurchase("coins_099") in button handler
     
  6. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Got it, we will try to reproduce. Are you able to test with the Sample IAP Project? I likely won't have time to check this for a couple of weeks, busy times.
     
  7. michaeltepl

    michaeltepl

    Joined:
    Dec 26, 2013
    Posts:
    22
    I checked your Sample IAP Project and found out that issue is caused by Development Build setting. When it is set to true I see error in console both in your and my projects, when it is disabled - everything works fine.
    With version 2.1.1 it worked fine in both build - Development and Regular
     

    Attached Files:

  8. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Wow, great catch! I will focus on that scenario and let the engineering team know. Thanks again, and sorry for the inconvenience. I will follow up.
     
  9. michaeltepl

    michaeltepl

    Joined:
    Dec 26, 2013
    Posts:
    22
    Thanks! It would be great it they could fix it ASAP, because I spent a lot of time seeking for previous version of this package
     
  10. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Well it will be in the next release, so not ASAP but in a few weeks likely. You can always revert to a backup of your project, which you should always do before any upgrade. Previous IAP versions are here https://forum.unity.com/threads/unity-iap-previous-versions.527432/#post-6506544
     
  11. michaeltepl

    michaeltepl

    Joined:
    Dec 26, 2013
    Posts:
    22
    Thanks a lot!