question

entelicon avatar image
entelicon asked

Unity Reference not set with StartPurchaseRequest

When running this in Unity, it says item is not set to an instance of an object. Am I just overlooking something?

void PurchaseItem() {
        ItemPurchaseRequest item = new ItemPurchaseRequest();
        item.ItemId = "10";
        item.Quantity = 1;
        item.Annotation = "Bought from store";


        StartPurchaseRequest purchaseRequest = new PlayFab.ClientModels.StartPurchaseRequest();
        purchaseRequest.Items[0] = item;


        PlayFabClientAPI.StartPurchase(purchaseRequest, (result) => {
            Debug.Log("Object DisplayName: " + result.Contents [4]);
        }, (error) => {


        });
    }
apis
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

"Object reference not set to an instance of an object" is a .Net error telling you you're trying to reference a null object - something that doesn't exist. Given that you're only trying to purchase one item in your code snippet, there won't be a Contents[4], only a Contents[0].

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.