Facebook IAP throwing exception



  • Hi,

    I'm looking to push my game to Facebook canvas. I've followed the instructions provided, but when the game starts, I get an error:

    NullReferenceException: Object reference not set to an instance of an object.
    UnityLoader.js:4   at UnityEngine.Purchasing.StandardPurchasingModule.Configure () [0x00000] in <00000000000000000000000000000000>:0 
    UnityLoader.js:4   at UnityEngine.Purchasing.Extension.AbstractPurchasingModule.Configure (UnityEngine.Purchasing.Extension.IPurchasingBinder binder) [0x00000] in <00000000000000000000000000000000>:0 
    UnityLoader.js:4   at UnityEngine.Purchasing.PurchasingFactory..ctor (UnityEngine.Purchasing.Extension.IPurchasingModule first, UnityEngine.Purchasing.Extension.IPurchasingModule[] remainingModules) [0x00000] in <00000000000000000000000000000000>:0 
    UnityLoader.js:4   at UnityEngine.Purchasing.ConfigurationBuilder.Instance (UnityEngine.Purchasing.Extension.IPurchasingModule first, UnityEngine.Purchasing.Extension.IPurchasingModule[] rest) [0x00000] in <00000000000000000000000000000000>:0 
    UnityLoader.js:4   at SIS.IAPManager.Initialize () [0x00000] in <00000000000000000000000000000000>:0 
    UnityLoader.js:4   at SIS.IAPManager.Awake () [0x00000] in <00000000000000000000000000000000>:0 
    

    I'm not using Playfab or anything else, I just want to use standard Unity IAP functionality.

    Thanks,

    Alan



  • Hey Alan, glad to see you on our new forum.

    This looks like the Unity bug I've replied to here as well:

    https://forum.unity.com/threads/nullreferenceexception-at-unityengine-purchasing-standardpurchasingmodule-configure.541272/

    In the IAPManager script, line 166 where it says

    builder = ConfigurationBuilder.Instance(...)
    

    could you try removing the "new SISPurchasingModule()" so that it only uses the StandardPurchasingModule? Note that any of our custom modules would not work then, if you are about to use them on other platforms.



  • Hi,

    Thanks for the info. I'll give it a try and see if it works. I'm only using standard stuff, so Facebook, iOS and GooglePlay for now, so its not a problem. The extra module is only for Playfab and Oculus right?

    Thanks

    Alan



  • Yes, everything related to PlayFab, Oculus and Steam. You can have a look at the contents of the SISPurchasingModule script for that, but it is correct that you don't need it when only using default Unity IAP stores.



  • Hi,

    Ok, so I tried making the change you suggested, but I still get the same null reference exception when the game starts up.

    I've changed it now to:

    builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    

    if it helps, you can access the game at https://apps.facebook.com/pdcdartsmatch



  • I've just built and uploaded a new WebGL app to Facebook using my old project setup:

    • Latest SIS version
    • Unity 5.6.0f3
    • Unity IAP 1.20.1
    • Facebook SDK 7.9.4

    I did use the Facebook platform in Unity and uploaded the build via their webhosting service. The build runs fine and does not throw any errors at launch, even with both

    builder = ConfigurationBuilder.Instance(new SISPurchasingModule(), StandardPurchasingModule.Instance());
    

    Closely looking at your error log, it seems like the issue is actually coming from the configuration, rather than the module initialization. As a test, could you comment out all of the calls to

    builder.Configure
    

    in the IAPManager's Initialize() method? Note that when commenting them out, e.g. Google Play won't work anymore with Unity IAP either. But maybe we'll get more details on the cause this way. Could you please post your setup as well, so I can test something similar to that?



  • Hi,

    My set up is as follows:

    • SIS 4.2
    • Unity 2018.3.8f1
    • Unity IAP 1.20.1
    • Facebook SDK 7.15.1

    I am also using their webhosting service, but from a manual ZIP upload produced by Unity Cloud Build.

    I'll run another build off and see if removing the configure stuff changes things. So Initialize() is now like this:

            public void Initialize()
            {
                #if UNITY_PURCHASING
                //initialized already
                if(controller != null)
                    return;
    
                //create Unity IAP builder
                builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
                RequestProductData(builder);
    
    //            builder.Configure<IGooglePlayConfiguration>().SetPublicKey(storeKeys.googleKey);
    //            builder.Configure<ITizenStoreConfiguration>().SetGroupId(storeKeys.tizenKey);
                //builder.Configure<IMoolahConfiguration>().appKey = storeKeys.moolahKey;
                //builder.Configure<IMoolahConfiguration>().hashKey = storeKeys.moolahHash;
    
                if (isDebug)
                {
    //                builder.Configure<IMicrosoftConfiguration>().useMockBillingSystem = true;
                    // Write out our Amazon Sandbox JSON file.
                    // This has no effect when the Amazon billing service is not in use.
    //                builder.Configure<IAmazonConfiguration>().WriteSandboxJSON(builder.products);
                    // Enable "developer mode" for purchases, not requiring real-world money
    //                builder.Configure<ISamsungAppsConfiguration>().SetMode(SamsungAppsMode.AlwaysSucceed);
                    //builder.Configure<IMoolahConfiguration>().SetMode(CloudMoolahMode.AlwaysSucceed);
                }
    
                //now we're ready to initialize Unity IAP
                UnityPurchasing.Initialize(this, builder);
                #endif
    
                //we use PlayFab (full) on a platform that does not utilize the PlayfabStore class,
                //yet we still want to request PlayFab's catalog items for remote overwrites
                #if PLAYFAB && !PLAYFAB_PAYPAL && !PLAYFAB_VALIDATION
                new PlayfabStore().RetrieveProducts(null);
                #endif
            }
    

    This is building now, so I'll let you know if it makes any difference.



  • Ok, just done a test and get the same error inside the StandardPurchasingModule.Configure()



  • Thanks for the follow up. That's as basic as it can get - in your latest code block there is not even Simple IAP System code involved anymore.

    I'm not sure what to investigate here honestly. I'll try to reproduce it with a similar setup soon, but if that fails too, I would go ahead and submit a bug report to Unity. You can do so as well, or post in the official Unity IAP forum, if you wish...


Log in to reply