Skip to content

Initializing the SDK

Now that you have installed the SDK and know how to configure it. Let's start the integration:

  1. Configure and initialize Usercentrics after app launch.

    using Unity.Usercentrics;
    

  2. Instantiate a 'UserOptions' object with your desired configuration

    1. Select the Usercentrics prefab at Plugins/Usercentrics.
    2. Configure it in the inspector: Inspector configuration
    3. Save the changes.
  3. Drag the Usercentrics prefab from Plugins/Usercentrics into your scene This gameobject must be present in an early scene of your game before any script that interacts with Usercentrics.

  4. Call Initialize() from the 'Usercentrics' instance, and provide completion blocks for both success and failure.

    Usercentrics.Instance.Initialize(
        (usercentricsReadyStatus) =>
        {
            // Success: Returns UsercentricsReadyStatus object
        },
        (errorMessage) =>
        {
            // Failure: Returns non-localized error
        }
    );
    
    On success, it'll be returned a UsercentricsReadyStatus1. Use this status to know if you need to collect consent or apply the already collected consent.

  5. 🚀 You are now ready to collect and apply consent.

Resetting the SDK

Initializing the SDK twice will lead to a crash. If you need to reset the configuration, please use reset(). This will clean all local storage and release the initialized instance. You may initialize the SDK again after this.

This is a recommended strategy for cases like:

  • Using mutiple settingsIDs on one app, to address different customers or user tiers.
  • Init failures due to unavailable connection or network error and you wish to retry. Make sure you know what you are doing, as you can easily end up in a loop of resets.
  • If a user logs out, you might wish to remove all local storage. Use restoreUserSession to restore a user's consent after login.
  • During development for testing, to clean the local storage.

Make sure you validate the expected behaviour, before using reset in production.


  1. This status will be loaded when the SDK is fully initialized.