NullReferenceException: Object reference not set to an instance of an object



  • NullReferenceException: Object reference not set to an instance of an object
    SIS.DBManager.GetPurchase (System.String id) (at Assets/SimpleIAPSystem/Scripts/DBManager.cs:246)
    Visyde.SampleMainMenu.Start () (at Assets/SuperMultiplayerShooter/Scripts/SampleMainMenu.cs:187)

    in DBManager.cs, on row 246, null error on if:

    if (instance.gameData[contentKey][id] != null)
                    return instance.gameData[contentKey][id].AsInt;
                else...
    

    I call this instruction:

    if (DBManager.isPurchased("usm.remove_ads"))
    

    the id exist!immagine



    • are you starting the game from a scene that contains the IAPManager prefab, and DBManager component? Or are they included in the same scene?
    • if you are calling your code in Awake, this won't work. The DBManager needs time to initialize and should be called in Start() at earliest.


  • @Baroni ok, adding the IAPMANAGER prefab in the opening scene works correctly.
    Thanks!


Log in to reply