> For the complete documentation index, see [llms.txt](https://docs.convai.com/api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.convai.com/api-docs/plugins-and-integrations/unity-plugin-beta-overview/features/dynamic-context/quick-start.md).

# Quick Start

## Get Your First Context-Aware Character Working

This guide walks you through a complete, working example: a character that knows which location the player is standing in, updated from a button click — no scripting required. You will add one component, configure one command, wire one event, and test everything in Play Mode, entirely from the Unity Inspector.

{% hint style="info" %}
**Prerequisites**

* A Unity scene with a `ConvaiCharacter` component already set up and working (the character should respond to speech).
* Your Convai API key is configured in **Tools → Convai → Configuration**.
  {% endhint %}

## Step-by-Step Setup

{% stepper %}
{% step %}
**Add the Dynamic Context Command component**

With the NPC GameObject selected, click **Add Component** and navigate to:

**Convai → Dynamic Context → Convai Dynamic Context Command**

The component appears in the Inspector with three sections: **Target**, **Command**, and **Events**.

<figure><img src="/files/CNCygx3B4eeQp9Z63MYO" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**Verify Auto Resolve Character**

In the **Target** section, confirm that **Auto Resolve Character** is enabled (it is on by default). This tells the component to find the `ConvaiCharacter` on the same GameObject automatically — you do not need to assign it manually.

{% hint style="warning" %}
If the Inspector shows a warning such as *"No ConvaiCharacter found on this GameObject. Assign one or disable Auto Resolve Character."*, confirm that both components are on the same GameObject.
{% endhint %}
{% endstep %}

{% step %}
**Configure a SetState command**

In the **Command** section:

* Set **Command Type** to `SetState` (the default).
* Set **State Name** to `Location`.
* Set **State Value** to `Fire Exit Corridor`.
* Leave **Reaction** set to `Auto`.

This command will tell the character that the current location is the fire exit corridor.
{% endstep %}

{% step %}
**Wire Execute() to a trigger**

Choose any event source that should fire the context update. For a quick test, use a UI **Button**:

1. Select your Button in the scene. If you don't have one, create a button first.
2. In the **On Click ()** event list, click the **+** button.
3. Drag the NPC GameObject into the object slot.
4. From the function dropdown, choose **ConvaiDynamicContextCommand → Execute**.

<figure><img src="/files/0i2jh02dApOeFWyoM55V" alt=""><figcaption></figcaption></figure>

You can also wire `Execute()` to `OnTriggerEnter`, an animation timeline signal, or any other `UnityEvent`.
{% endstep %}

{% step %}
**Enter Play Mode and test**

Press **Play**. Start a conversation with the character, then click the button (or trigger the event). Ask the character *"Where am I?"* or *"What's at this location?"* and confirm it responds with awareness of the fire exit corridor.
{% endstep %}
{% endstepper %}

{% hint style="success" %}
**Expected result:** After triggering `Execute()`, the character's next response references the location you set. If the character does not acknowledge the location, open the Unity Console and look for warnings logged by `ConvaiDynamicContextCommand`. See [Troubleshooting & Diagnostics](/api-docs/plugins-and-integrations/unity-plugin-beta-overview/features/dynamic-context/troubleshooting-and-diagnostics.md) for a complete diagnostic guide.
{% endhint %}

## What Just Happened

When you clicked the button, the following occurred:

1. The button's **On Click** event called `Execute()` on the `ConvaiDynamicContextCommand` component.
2. The component resolved the `ConvaiCharacter` on the same GameObject and validated the configuration.
3. `SetState("Location", "Fire Exit Corridor")` was called on the character's Dynamic Context interface.
4. The SDK's internal tracker recorded the new state.
5. Because the character was already in conversation, a `context-update` message was sent immediately to the Convai backend.
6. The backend injected the context into the character's reasoning, making it available for the next conversational turn.

If `Execute()` had fired before the conversation started, the state would have been queued and sent automatically when the session began — nothing is lost. For a precise breakdown of all timing scenarios, see [Sync Behavior and Timing](/api-docs/plugins-and-integrations/unity-plugin-beta-overview/features/dynamic-context/sync-behavior-and-timing.md).

{% hint style="info" %}
The SDK ships a ready-made **Sample Dynamic Context UI** prefab for testing all context operations at runtime without building custom UI. Find it at `Packages/com.convai.convai-sdk-for-unity/Prefabs/SampleDynamicContextUI.prefab` — drop it into your scene and assign the character reference.
{% endhint %}

## What's Next

* [Command Component Reference](/api-docs/plugins-and-integrations/unity-plugin-beta-overview/features/dynamic-context/command-component-reference.md) — all six command types, every field, and every validation warning in full detail.
* [Static Context at Connection Time](/api-docs/plugins-and-integrations/unity-plugin-beta-overview/features/dynamic-context/static-context-at-connection-time.md) — set a fixed scenario description that the character knows before the first word is spoken.
* [Scripting API Reference ](/api-docs/plugins-and-integrations/unity-plugin-beta-overview/features/dynamic-context/scripting-api-reference.md)— drive Dynamic Context from C# when your game logic demands it.

## Conclusion

You have a working Dynamic Context integration driven entirely from the Inspector. The `ConvaiDynamicContextCommand` component and the `ConvaiCharacter.DynamicContext` scripting API share the same underlying tracker — everything you set up here scales directly into scripted systems. Explore the [Command Component Reference](/api-docs/plugins-and-integrations/unity-plugin-beta-overview/features/dynamic-context/command-component-reference.md) for the full range of command types available.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.convai.com/api-docs/plugins-and-integrations/unity-plugin-beta-overview/features/dynamic-context/quick-start.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
