IAP not working. Debug window not showing up due to NullReferenceException

I’ve been checking several forums threads, watched tutorials but this problem seems quite unusual.
Here is the error log, any idea what causes it?

NullReferenceException: Object reference not set to an instance of an object
UnityEngine.Purchasing.UIFakeStore.InstantiateDialog () (at Library/PackageCache/com.unity.purchasing@3.0.1/Runtime/Stores/FakeStore/UIFakeStore.cs:175)
UnityEngine.Purchasing.UIFakeStore.StartUI (System.String queryText, System.String okayButtonText, System.String cancelButtonText, System.Collections.Generic.List1[T] options, System.Action2[T1,T2] callback) (at Library/PackageCache/com.unity.purchasing@3.0.1/Runtime/Stores/FakeStore/UIFakeStore.cs:153)
UnityEngine.Purchasing.UIFakeStore.StartUI[T] (System.Object model, UnityEngine.Purchasing.FakeStore+DialogType dialogType, System.Action2[T1,T2] callback) (at Library/PackageCache/com.unity.purchasing@3.0.1/Runtime/Stores/FakeStore/UIFakeStore.cs:128) UnityEngine.Purchasing.FakeStore.FakePurchase (UnityEngine.Purchasing.ProductDefinition product, System.String developerPayload) (at Library/PackageCache/com.unity.purchasing@3.0.1/Runtime/Stores/FakeStore/FakeStore.cs:163) UnityEngine.Purchasing.FakeStore.Purchase (System.String productJSON, System.String developerPayload) (at Library/PackageCache/com.unity.purchasing@3.0.1/Runtime/Stores/FakeStore/FakeStore.cs:132) UnityEngine.Purchasing.JSONStore.Purchase (UnityEngine.Purchasing.ProductDefinition product, System.String developerPayload) (at Library/PackageCache/com.unity.purchasing@3.0.1/Runtime/Stores/BaseStore/JSONStore.cs:354) UnityEngine.Purchasing.PurchasingManager.InitiatePurchase (UnityEngine.Purchasing.Product product, System.String developerPayload) (at Library/PackageCache/com.unity.purchasing@3.0.1/Runtime/Purchasing/PurchasingManager.cs:60) UnityEngine.Purchasing.PurchasingManager.InitiatePurchase (System.String purchasableId, System.String developerPayload) (at Library/PackageCache/com.unity.purchasing@3.0.1/Runtime/Purchasing/PurchasingManager.cs:69) UnityEngine.Purchasing.PurchasingManager.InitiatePurchase (System.String productId) (at Library/PackageCache/com.unity.purchasing@3.0.1/Runtime/Purchasing/PurchasingManager.cs:43) UnityEngine.Purchasing.CodelessIAPStoreListener.InitiatePurchase (System.String productID) (at Library/PackageCache/com.unity.purchasing@3.0.1/Runtime/Codeless/CodelessIAPStoreListener.cs:145) UnityEngine.Purchasing.IAPButton.PurchaseProduct () (at Library/PackageCache/com.unity.purchasing@3.0.1/Runtime/Codeless/IAPButton.cs:108) UnityEngine.Events.InvokableCall.Invoke () (at <a9810827dce3444a8e5c4e9f3f5e0828>:0) UnityEngine.Events.UnityEvent.Invoke () (at <a9810827dce3444a8e5c4e9f3f5e0828>:0) UnityEngine.UI.Button.Press () (at C:/Program Files/Games/2020.1.5f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Button.cs:68) UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/Program Files/Games/2020.1.5f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Button.cs:110) UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/Program Files/Games/2020.1.5f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:50) UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction1[T1] functor) (at C:/Program Files/Games/2020.1.5f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:261)
UnityEngine.EventSystems.EventSystem:Update() (at C:/Program Files/Games/2020.1.5f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:376)

If you haven’t already, Go to Services > In App Purchasing and scroll down to Welcome section where you’ll find a button to import further IAP files for each store. It would say “Reimport” if you’ve already done this (Screenshot below).

This will import files under Assets > Plugins > UnityPurchasing. If you were following the note written in package manager about upgrading to 3.0.1 and avoiding compile errors, then you might have removed the entire UnityPurchasing folder in this directory as the intsructions aren’t exaclty clear on which folders need removed. I think you can delete the rest but leave Assets > Plugins > UnityPurchasing > Resources and its contents to avoid that error you’re having. That’s because UIFakeStore.cs is trying to find the prefab living in that folder.

2 Likes

I am also seeing inconsistent behavior when I delete the /Library folder, we are checking further.

In my case, I was able to resolve the issue by deleting the /Library folder. I noticed the following at the top of the tangle files

#if UNITY_ANDROID || UNITY_IPHONE || UNITY_STANDALONE_OSX || UNITY_TVOS

but I’m on Windows. Deleting the #if statement worked for me.

I also did migration from IAP 2.1.0 to 3.0.2 and noticed this problem: plugin instruction says we need to delete Plugins/UnityPurchasing folder, because whole plugin is moved to the Packages. However, this package doesn’t have Resources/UIFakeStoreCanvas.prefab.

To get this prefab we have to options:

  1. Save it before deleting folder from Plugins
  2. Import Sample IAP project from PackageManager - this will create Samples folder with Resources/UIFakeStoreCanvas.prefab
2 Likes

Yes, this is an issue we are working on.

do you know approx when it will be fixed?

1 Like

The above workaround worked for me.
If you have deleted the Assets > Plugins > UnityPurchasing as in the instruction and installed from Package manager then go to the IAP window and reimport only by ticking Assets > Plugins > UnityPurchasing > Resources leaving rest unticked. Saves you some time.

Fixed this issue by just importing samples under unity IAP from package manager! anyway this miust have been fixed!
my unity version 2021.1.6

1 Like

The current version is 2021.1.7 and plugin version 3.0.2 still needs samples to be downloaded in order to fix this error.

1 Like

Good point! This should be fixed in IAP 4.0.3 that is currently available

1 Like