---
metadata:
  - name: generator
    content: Diplodoc Platform v5.55.3
alternate:
  - https://yandex.com/support/varioqub-app/en/sdk/plugins/unity/integration.md
  - https://yandex.com/support/varioqub-app/ru/sdk/plugins/unity/integration.md
  - href: https://yandex.com/support/varioqub-app/en/sdk/plugins/unity/integration.md
    type: text/markdown
    title: Markdown version
  - href: https://yandex.com/support/varioqub-app/en/llms.txt?revision=r20853974
    rel: describedby
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/support/varioqub-app/en/llms.txt?revision=r20853974

# Varioqub Unity integration

[Varioqub Unity](https://github.com/appmetrica/varioqub-unity-plugin) is a plugin for the [Unity3D](http://docs.unity3d.com/) game development platform. It includes the Varioqub SDK support for [Android](https://yandex.com/support/varioqub-app/en/sdk/android/integration.md) and [iOS](https://yandex.com/support/varioqub-app/en/sdk/ios/integration.md).

**System requirements:**

- Unity 2018.3 or later.
- [External Dependency Manager](https://github.com/googlesamples/unity-jar-resolver).

To use the Varioqub Unity plugin, add and initialize the AppMetrica Unity plugin. For more information on how to do this, see the [AppMetrica Unity documentation](https://appmetrica.yandex.com/docs/en/sdk/unity/analytics/quick-start).

Follow this step-by-step guide to enable and initialize Varioqub Unity.

## General integration recommendations

1. When starting a new session, call the `ActivateConfig()` method to retrieve the stored flag values.

1. Run `Fetch()` in the background to export the new flag values from the server and activate them when the next session starts.

1. We don't recommend calling the `ActivateConfig()` method mid-session because it can cause inconsistent app behavior.

## Step 1. Enable the Varioqub Unity plugin {#integration}

{% list tabs %}

- OpenUPM

  Add the following dependencies to [Packages/manifest.json](https://docs.unity3d.com/Manual/upm-manifestPrj.html):

  ```json
  {
    "scopedRegistries": [
      {
        "name": "package.openupm.com",
        "url": "https://package.openupm.com",
        "scopes": [
          "com.google.external-dependency-manager",
          "com.yandex.varioqub"
        ]
      }
    ],
    "dependencies": {
      "com.google.external-dependency-manager": "1.2.183",
      "com.yandex.varioqub": "https://github.com/appmetrica/varioqub-unity-plugin"
    }
  }
  ```

- UPM (GitHub)

  1. Follow the [documentation](https://github.com/googlesamples/unity-jar-resolver/tree/master?tab=readme-ov-file#getting-started) to enable External Dependency Manager.

  2. Add the Varioqub Unity plugin to the dependencies in [Packages/manifest.json](https://docs.unity3d.com/Manual/upm-manifestPrj.html):

    ```json
    {
      "dependencies": {
        "com.yandex.varioqub": "https://github.com/appmetrica/varioqub-unity-plugin.git#vhttps://github.com/appmetrica/varioqub-unity-plugin"
      }
    }
    ```

{% endlist %}

## Step 2. Initialize the library

Initialize the Varioqub library using the `initVarioqubWithAppMetricaAdapter()` method:

```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Com.Yandex.Varioqub;

public class VarioqubSDK : MonoBehaviour {
    IEnumerator RepeatFetch() {
        while (true) {
            Varioqub.Fetch(
                onSuccessDelegate: () => {
                    Debug.Log("Fetch succeeded!");
                },
                onErrorDelegate: error => {
                    Debug.Log($"Error: {error}!");
                }
            );
            yield return new WaitForSeconds(10f);
        }
    }

    void Awake() {
        var settings = new VarioqubSettings("appmetrica.1234567");
        settings.Logs = true;
        settings.ThrottleInterval = 2;
        settings.ClientFeatures = new Dictionary<string, string>(){
            {"isNight", "true"}
        };

        Varioqub.InitVarioqubWithAppMetricaAdapter(settings);
        Varioqub.ActivateConfig();

        StartCoroutine(RepeatFetch());
    }
}
```

To initialize the library, use the `initVarioqubWithAppMetricaAdapter(VarioqubSettings settings)` method. It takes a `VarioqubSettings` object as a parameter.

It contains required and optional settings.

**Required**

- `clientID`: Project ID specified as `appmetrica.XXXXXX`, where _XXXXXX_ is the app ID from the AppMetrica interface. For example, `VarioqubSettings("appmetrica.1234567")`.

    <!-- source: en/sdk/_includes/application-id.md -->
    {% note tip %}

    You can find the app ID on the **Settings** page in AppMetrica: copy it from **General settings** → **App ID**.

    {% endnote %}
    <!-- endsource: en/sdk/_includes/application-id.md -->

**Optional**

- `ClientFeatures`: List of custom parameters. For example, you can pass a flag indicating if the user is subscribed to newsletters.

- `ThrottleInterval`: Interval between config updates, in seconds. This is only recommended for testing purposes.

- `URL`: Changes the URL for server responses. Only used for testing.

- `Logs`: Enables internal logging. To help us diagnose your problem, please enable logging and attach the log file with a description of the problem when submitting your support request.

- `activateEvent`: Sends an event when the flag configuration is activated. Event sending is enabled by default.

## Step 3. Set the default configuration

You can set a default configuration so your app uses the required parameter values before it connects to a server with remote configuration. To do this, pass the list of parameters using the method `SetDefaults(IDictionary<string, object> defaults)`.

You can download the default XML configuration file on the [Flag configuration](https://yandex.com/support/varioqub-app/en/web/config.md#create) page.

## Step 4. Run a background update of the flag configuration and activate it

To use the most recent flag configuration from the interface, run a background configuration update using the `Fetch()` method.

```csharp
Varioqub.Fetch(
    onSuccessDelegate: () => {
        Debug.Log("Fetch succeeded!");
    },
    onErrorDelegate: error => {
        Debug.Log($"Error: {error}!");
    }
);
```

Each time you receive the latest version of the configuration (most often this occurs when starting a new session), you need to activate it using the `ActivateConfig()` method.

<!-- source: en/sdk/_includes/config-note.md -->
{% note tip %}

Main use case:

Regularly download the configuration and activate it when the app is launched. That guarantees your flags won't change during user sessions. We recommend launching activation as soon as possible.

{% endnote %}
<!-- endsource: en/sdk/_includes/config-note.md -->

```csharp
Varioqub.ActivateConfig();
```

## Getting flags from the interface

Flag values are retrieved and returned in the following order:

1. Flag is present in the experiment.
2. Flag is present in the loaded configuration.
3. Flag is present in the default configuration.

Flag getters:

- `Varioqub.GetString(key, default)`.

Code example:

```csharp
Varioqub.GetString("key", "default_value");
```

## Obtaining the device ID to test the experiment {#get-id}

To get the device ID, use the `Varioqub.GetId()` method:

```csharp
Varioqub.GetId();
```

{% note info %}

Before the first successful `Fetch()` call, the `Varioqub.GetId()` method may return empty responses.

{% endnote %}

To learn more about creating and testing experiments, see [Creating an experiment](https://yandex.com/support/varioqub-app/en/web/create.md).


<!-- source: en/_includes/feedback.md -->
<details>
    <summary class="button">Contact support</summary>
    <div style="padding: 15px;
     margin: 10px 0;
     background: #FFFFFF;
     border-radius: 10px;
     border: 1px solid var(--yc-color-line-generic);">
     <iframe style="background: #FFFFFF;"
        height="700"
        width="100%"
        frameborder="0"
        src="https://forms.yandex.com/surveys/2617/?iframe=1&lang=en">
    </iframe>
</details>


<!-- endsource: en/_includes/feedback.md -->

