Q4 2023 > IAP in modern Unity

As many of us know, time goes by, and quite a few things have changed about IAP.
Some things/questions from modern IAP:

-IAP Button new script-
On Purchase Failed requires now:
void OnPurchaseFailed(Product product, PurchaseFailureDescription failureDescription)
image
As I have seen, you have to drag the button itself and that’s it. There is no text to show the title and description as I see (so that will be done manually I guess).

void OnProductFetched(Product product):
I imagine that here we check if you have already bought the product so that you don’t buy it twice (‘if’ with the playerPrefs and if we already have this product return).

Question 1:
I dont understand restore purchase button, I will remove it. It doesn’t seem to do anything, and if you buy something you don’t return it (or so I’ve understood).

Question 2:
Some warning


If I follow https://docs.unity.com/ugs-overview/services-core-api.html#InitializationExample steps, still warning, so I dont undertand (I change script execution order to be first script and nothing…).

I hope to help someone, and that someone can help me with the questions, thank you!
Have a good day!

Create an empty scene and call it Bootstrap
Within the empty scene create an empty GameObject and add this script:

using System;
using Unity.Services.Core;
using Unity.Services.Core.Environments;
using UnityEngine;
 
public class InitializeUGS : MonoBehaviour {
    
    public string environment = "production";
 
    async void Start() {
        try {
            var options = new InitializationOptions()
                .SetEnvironmentName(environment);
 
            await UnityServices.InitializeAsync(options);
        }
        catch (Exception exception) {
            Debug.LogError($"UGS Exception {exception}");
            return;
        }
        Debug.Log($"UGS Initialized");
        SceneManager.LoadScene(1);
    }
}

Save this scene and add it to your Build menu making it the first scene in the Build Order, making your menu or game scene scene 1 (depending on your workflow).

When you start the game, you’ll need to start it from this scene to ensure that UGS services are properly initialized.

About this, I saw that the warning was still displayed, so with this script update it works!

Thanks Brian you for the Bootstrap scene reminder hahahaha.

1 Like

The bootstrap idea is something that SHOULD be on their instructions. While it seems patently obvious to folks who have done this sort of async with initialization requirements before, it’s not that obvious from their instructions. Even with Awake(), async operations won’t resolve before everybody elses Awake() methods are called, so other operations end up failing.

In my big game project, I go from here to the main menu where I check to see if the player is authenticated and either have the player log in or create a new account, then from there, I go to a character screen where the player can select from their saved characters, and finally to the game scene where the player can actually start fight.

I am agree, thanks master

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms