---
title: "Pass data to flows in Unity SDK"
description: "Pass a value from your Unity app to a flow, and show it in a text element."
---

> **AI agents**: to search Adapty docs faster and with fewer tokens, install the Adapty skill. Claude Code (self-updating via plugin): `claude plugin marketplace add adaptyteam/adapty-skills && claude plugin install adapty-skills@adapty` — other tools: `npx skills add adaptyteam/adapty-skills --all`

A [custom tag](flow-custom-tags) is a custom variable with a value from your app. After you select **Value comes from outside the app** in a variable's settings, your app can set its value through the Adapty SDK. For example, a text element contains "Coins:" and a custom tag. If your app passes "120" for the tag, users see "Coins: 120".

## Before you start

You need the Adapty SDK v4 or later. Versions before v4 don't display flows.

## Add custom tags to the flow

To show your app's values in a flow, set up custom tags in the builder:

1. [Create a custom tag](flow-custom-tags#create-a-custom-tag) for each value that your app passes.

   <ZoomImage id="flow-custom-tag-create.webp" width="500px" alt="Create variable form with a name, a description, the String value type, and an initial value" />

2. [Insert each tag into a text element](flow-custom-tags#add-a-custom-tag-to-a-text-element).
3. Note each tag's full name, including its group. Your app's code passes each value under this name. For example, if the `user` group contains a `streak` tag, the tag's full name is `user.streak`.

   <ZoomImage id="flow-custom-tag-full-name.webp" width="500px" alt="Custom tab of the Add variable dropdown with the streak tag in the user group" />

## Pass custom tag values

Pass your app's values to the `SetCustomTags` method of an `AdaptyUICreateFlowViewParameters` object, as a string-to-string dictionary, such as a `Dictionary<string, string>`, and call `AdaptyUI.CreateFlowView` with that object:

- Each key is the full name of a custom tag, such as `user.streak`.
- Each value is the string that users see in place of the tag.
- Each value must be human-readable, such as "1,250", not "1250.0". Adapty doesn't format or translate it.

The SDK reads the values once, when it creates the view, so they don't change while the flow is open.

```csharp showLineNumbers title="Unity"
var parameters = new AdaptyUICreateFlowViewParameters()
    .SetCustomTags(new Dictionary<string, string> {
        { "username", "DragonSlayer42" },
        { "coins", "1,250" }
    });

AdaptyUI.CreateFlowView(flow, parameters, (view, error) => {
    if (error != null) {
        // handle the error
        return;
    }

    // present the view
});
```

To test your custom tags, open the flow in your app, after you add the code that sets their values. The builder canvas and the [preview on devices](paywall-device-compatibility-preview#preview-on-devices) only show Initial values: the Adapty mobile app doesn't set custom tag values.

If your app already sets custom tag values for old Paywall Builder paywalls, review [how custom tags in flows differ](migrate-to-flows#custom-tags-from-the-old-paywall-builder).

## What users see without a value

Users see a custom tag's **Initial value** as a fallback in the following cases:

- Your app passes no value for the tag.
- The user hasn't updated your app to a version that passes the value.
- The name in your app's code doesn't match the tag's full name, including letter case.
- Another custom tag in the same text element has no value. Then every custom tag in that text element shows its Initial value.

To show nothing in place of a tag, pass an empty string. Adapty treats an empty string as a value, so the fallback doesn't appear.

## Example: show a BMI from onboarding answers

A flow can collect answers from users, and a custom tag can show a value from your app. Combine the two to show users a result that your app calculates from their answers, such as a score, a recommended plan, or a health metric:

1. A flow collects the answers and sends them to your app.
2. Your app calculates the result.
3. Your app passes the result to the next flow as a custom tag value.

In this example, an onboarding flow collects the user's weight and height. When the user closes the onboarding flow after its last screen, your app calculates their body mass index (BMI). Then it opens a paywall flow that shows the BMI.

### Set up the flows

1. [Create two flows](paywall-builder-templates): an onboarding flow that collects the user's weight and height, and a paywall flow that shows their BMI.
2. Add two [**Number** inputs](builder-inputs-and-forms) to the onboarding flow:
   - One for the weight in kilograms, with the **Element ID** `weight`.
   - One for the height in centimeters, with the **Element ID** `height`.

   For both inputs, set the **Format** to **Integer**. An input sends its value as text, exactly as the user types it, and the [sample code](#pass-the-bmi-to-the-paywall) doesn't read "70.5" and "70,5" the same way. Whole numbers have no decimal separator, so the code reads them the same in every locale.
3. To make sure your app receives both values, end the onboarding flow with a screen that has no inputs. On that screen, add a button with the [**Close flow**](onboarding-actions#close-flow) action. Inputs send their values when they lose focus or when the user moves to another screen. The Close flow action doesn't send them. The sample code only opens the paywall if the user reached the last screen.
4. In the paywall flow, [create a custom tag](flow-custom-tags#create-a-custom-tag) named `bmi`. In the **Initial value** field, enter a dash (`—`). Users see the dash if your app passes no BMI.
5. Add a text element with the words "Your BMI:" to the paywall flow. After these words, [insert the `bmi` custom tag](flow-custom-tags#add-a-custom-tag-to-a-text-element).
6. Add the onboarding flow to a [placement](placements), such as `onboarding`. Add the paywall flow to a placement with the ID `bmi_paywall`. The code in [Pass the BMI to the paywall](#pass-the-bmi-to-the-paywall) fetches the paywall by this ID.

### Pass the BMI to the paywall

Collect the weight and the height from the onboarding flow's `flow_user_input` events, as in [Process data from flows](unity-flow-input). To know that the user reached the last screen, watch for a `flow_screen_showed` event with `is_last_screen` set to `true`, as in [Track flow screen views](unity-flow-screen-views). When the user closes the onboarding flow after that screen, calculate the BMI. Then create the paywall's view, and pass the BMI for the `bmi` custom tag.

Implement the following methods on the listener you register with `Adapty.SetFlowsEventsListener`. `FlowViewDidDisappear` fires only after your app dismisses the onboarding flow, so the listener must also handle the **Close flow** action, as in [Close flows and paywalls](unity-handle-paywall-actions#close-flows-and-paywalls):

```csharp showLineNumbers title="Unity"
private readonly Dictionary<string, string> bodyAnswers = new Dictionary<string, string>();
private bool reachedLastScreen;

public void FlowViewDidReceiveAnalyticEvent(
    AdaptyUIFlowView view,
    string name,
    IReadOnlyDictionary<string, object> parameters
) {
    if (name == "flow_screen_showed") {
        if (parameters.TryGetValue("is_last_screen", out var lastScreen)
            && lastScreen is bool isLast && isLast) {
            reachedLastScreen = true;
        }
        return;
    }
    if (name != "flow_user_input") return;
    if (!parameters.TryGetValue("value", out var raw) || !(raw is string value)) return;

    if (!parameters.TryGetValue("element_id", out var idRaw) || !(idRaw is string elementId)) return;

    bodyAnswers[elementId] = value;
}

public void FlowViewDidDisappear(AdaptyUIFlowView view) {
    // The listener receives events from every flow. Reset `bodyAnswers` and
    // `reachedLastScreen` whenever a flow disappears, so that the paywall
    // doesn't open again when the user closes it.
    var answers = new Dictionary<string, string>(bodyAnswers);
    var finished = reachedLastScreen;
    bodyAnswers.Clear();
    reachedLastScreen = false;

    // Number inputs send their values as strings.
    if (!finished) return;
    if (!answers.TryGetValue("weight", out var weightText)
        || !double.TryParse(weightText, out var weight)) return;
    if (!answers.TryGetValue("height", out var heightText)
        || !double.TryParse(heightText, out var height)
        || height <= 0) return;

    var heightInMeters = height / 100;
    var bmi = weight / (heightInMeters * heightInMeters);
    ShowBmiPaywall(bmi.ToString("0.0"));
}

private void ShowBmiPaywall(string bmi) {
    Adapty.GetFlow("bmi_paywall", (flow, flowError) => {
        if (flowError != null) {
            // handle the error
            return;
        }

        var parameters = new AdaptyUICreateFlowViewParameters()
            .SetCustomTags(new Dictionary<string, string> { { "bmi", bmi } });

        AdaptyUI.CreateFlowView(flow, parameters, (view, viewError) => {
            if (viewError != null) {
                // handle the error
                return;
            }

            view.Present((presentError) => {
                if (presentError != null) {
                    // handle the error
                }
            });
        });
    });
}
```

`ToString("0.0")` uses the decimal separator of the current culture: "22.7" in English, "22,7" in German.

### Save the BMI to the user's profile

To show users different flows based on their BMI, save it as a [custom attribute](unity-setting-user-attributes#custom-user-attributes) of their profile. In the Adapty Dashboard, [create a **Number** custom attribute](segments#custom-attributes) with the key `bmi`. Then show each flow to an [audience](audience) built from the attribute.

Call the `Adapty.UpdateProfile` method in `FlowViewDidDisappear`, right after the line that calculates `bmi`. Pass that `double`, not the formatted string, so that a segment can compare the BMI with a threshold:

```csharp showLineNumbers title="Unity"
var parameters = new AdaptyProfileParameters.Builder()
    .SetCustomDoubleAttribute("bmi", bmi)
    .Build();

Adapty.UpdateProfile(parameters, (error) => {
    if (error != null) {
        // handle the error
    }
});
```