# User interface

!!! note "Summary"
    A **Dialogue Skin** decides what a conversation looks like on screen. When a conversation starts, the Skin creates its interface from a prefab built with **Unity UI** or **UI Toolkit**, updates it with every line and choice, and puts it away when the conversation ends.

![A conversation in Play mode using the Default (UGUI) sample Skin](../assets/ui-cover.jpg)

## Create a Dialogue Skin

1. Right-click the destination folder in the Project window.
2. Choose `Create` &rarr; `Game Creator` &rarr; `UI` &rarr; `Dialogue` &rarr; `Dialogue Skin`.
3. Choose **Unity UI** or **UI Toolkit** in the **UI** field.
4. Assign your interface prefab to the **Prefab** field that appears below it.

A new Skin starts on **Unity UI**. Both options take a single prefab, but they expect different things inside it: a **Dialogue UI** component for Unity UI, or a **Panel Renderer** with a UXML document for UI Toolkit.

![The Dialogue Skin asset inspector with multiple options](../assets/ui-skin.jpg)

The Inspector checks the prefab while you edit the Skin. A missing prefab, or one the chosen option can't drive, shows as an error under the **UI** field. If you start a conversation anyway, the Skin logs the same error to the Console and the conversation runs with no interface.

## Choose Unity UI or UI Toolkit

Both options show the same information and follow the same rules, so a Script behaves the same with either. They differ in how you tell the Skin where each piece of information goes:

<div class="grid cards" markdown>

- [**Unity UI:**](unity-ui.md) A Canvas prefab with a **Dialogue UI** component. You drag texts, images, and game objects into its fields.
- [**UI Toolkit:**](ui-toolkit.md) A **Panel Renderer** prefab with a UXML document. You give elements names or classes such as `gc-dialogue-speech-text`, and style the conversation's states with USS.

</div>

If the rest of your game's interface already uses one of them, use the same one here, so menus and conversations share fonts, input handling, and draw order.

## Configure the Skin

The rest of the Skin's fields apply to every conversation that uses it, whichever UI option you chose:

| Field | Controls |
| :--- | :--- |
| **Show Text During Choice** | Whether the last line stays on screen while the player reads the choices. When it's off, the speech box hides as soon as the choices appear. |
| **Show Text During Command** | Whether the current line stays on screen while a Command runs, such as a `@run` that opens a shop. When it's off, the speech box hides when the Command starts. |
| **Include Choices In Logs** | Whether the choice the player picks is added to the conversation log, between the lines. |
| **On Start** | Instructions that run when a conversation begins. |
| **On Finish** | Instructions that run when a conversation ends, whether it reached its last line or was stopped. |

**On Start** and **On Finish** are the place for anything every conversation with this Skin should do, such as stopping the player's movement and restoring it afterward. Both receive the Dialogue's game object as **Self** and **Target**; with **Play Script**, that's the temporary Dialogue it creates.

Neither blocks the conversation. The first line appears without waiting for **On Start** to finish, and the interface closes in the same frame **On Finish** starts.

!!! warning "On Finish can't animate the interface closed"
    The Skin deactivates the interface right after **On Finish** starts, so a closing animation on the prefab never plays. Use **On Finish** to restore game state, such as the player's movement or the camera.

## Use the Skin

Assign the Skin to the **Skin** field of **Play Dialogue** or **Play Script**. You can choose a different Skin each time you play a conversation, so one **Dialogue** component can use a speech bubble for small talk and a full-screen layout for a cutscene.

Leaving **Skin** empty runs the Script without an interface. Use that for background conversations driven entirely by code, and assign a Skin whenever the player must read text or pick a choice.

Without a Skin, nothing calls **Continue Script** or **Pick Script Choice** for you. An **Interact** line or a choice menu then waits until your own Instructions or code call them, so use automatic progression or provide that input yourself.

## What happens during a conversation

When a conversation starts, the Skin takes an instance of its prefab from a pool and activates it. If another conversation is already using that instance, the pool creates a second one, so two conversations can be on screen at the same time.

While the Script runs, the interface follows it:

1. Each text line appears in a speech box, revealed by its Actor's **Text Effect**.
2. When the Script reaches choices, the interface lists them, numbers them, and gives focus to the first one the player can pick.
3. Each finished line, and each picked choice when **Include Choices In Logs** is on, is added to the log, if the interface has one.
4. When the conversation ends or is stopped, the Skin clears the interface, deactivates the instance, and returns it to the pool.

If the player changes the language mid-conversation, the current line, the choices, and the log are redrawn in the new language.

!!! info "The prefab instance is reused"
    The pool deactivates the instance instead of destroying it. Components in the prefab receive `OnEnable` and `OnDisable` with each conversation, but `Awake` only once, so reset any state of your own in `OnEnable`.

## What the interface shows

Each line, choice, and log entry carries the same information about who says it. The interface reads it from the Actor in the [Compendium](../compendiums.md#actors) and from the Expression the Script names:

| Information | Comes from |
| :--- | :--- |
| Actor name and description | The Actor's **Name** and **Description**. |
| Actor portrait and color | The Actor's **Sprite** and **Color**. |
| Expression portrait and color | The **Sprite** and **Color** of the Expression the line names. Present only when the line names one of the Actor's Expressions. |
| Position on screen | The Actor's **Game Object**, used to [follow the speaker](#follow-the-speaker). |

A narrator line, written without an Actor, has none of this. Both UI options let you show a group of elements only when it has something to show: an Actor's name tag only on lines with an Actor, a portrait frame only on lines with an Expression. That way, a narrator line doesn't leave an empty frame on screen.

Beyond the speaker, the interface can show:

- **The line's text**, as the Text Effect reveals it.
- **A continue hint**, such as an arrow, while a press would move to the next line. See [Continue and pick choices](#continue-and-pick-choices).
- **Each choice's text and number.** The number is its position on screen, starting at `1`, after any shuffling.
- **Each choice's state:** whether it has a Condition, whether the player can pick it, and whether they picked it in an earlier conversation.
- **A timer** for timed choices, as the remaining seconds and as a bar that empties.
- **A log** of the lines already said, like a chat history.

!!! tip "Visited choices need line IDs"
    A choice counts as visited when the player picked it before, which Dialogue tracks through the choice's `id`. Click **Generate IDs** in the Script's **[Settings](../scripts.md#settings)** to give every choice one. The visited state lives on the **Dialogue** component, and a **Remember** component saves it between sessions.

## Continue and pick choices

The interface turns the player's input into two requests: continue to the next line, and pick a choice.

Continuing only affects lines whose Script uses the **Interact** mode; **Timeout** and **Audio** lines move on by themselves and ignore it. While a Text Effect such as **Typewriter** is still revealing a line, the first press shows the whole line and the second moves on. The continue hint appears only when a press would move on: on an **Interact** line that has finished revealing its text.

Picking a choice the player can't take, because its Condition failed, does nothing. Both UI options also disable that choice's button, so it doesn't look clickable.

Both options handle clicks for you: on the continue button and on each choice. Keyboard and gamepad shortcuts come from **Events** inside the prefab, and every sample prefab includes the same set:

| Event | Trigger | Instruction |
| :--- | :--- | :--- |
| `Event_Continue` | **On Keyboard Press** (`Space`) and **On Gamepad Press**. The Unity UI samples add **On Mouse Press**. | **Continue Script** |
| `Event_Choice_1` to `Event_Choice_6` | **On Keyboard Press**, keys `1` to `6`. | **Pick Script Choice**, with **Index** `0` to `5` and **Mode** set to **Shuffled Order**. |

**Pick Script Choice** counts from `0`, so the choice numbered `1` on screen is **Index** `0`. **Shuffled Order** picks by position on screen, which is what a number key should do when **Shuffle Choices** is on.

![The Event_Choice_1 Event inside a sample prefab](../assets/ui-event-pick-choice.jpg)

Because these Events live inside the prefab, they listen only while the interface is open. Each needs to know which Dialogue it talks to. The Unity UI samples use **Dialogue in Dialogue UI**, which is always the conversation that interface shows. The UI Toolkit samples use **Last Dialogue Started**, which is correct as long as only one conversation is on screen at a time.

When the choices appear, focus goes to the first choice the player can pick. The player can then move between choices with the arrow keys or a gamepad and confirm with the submit button, as with any menu.

## Speech boxes and Expressions

An interface can have more than one speech box. The first is the default and shows every line, unless the line's Expression asks for another one: set the Expression's **Speech** field to **Id** and enter the identifier of the box it should use.

For example, give a guard an `angry` Expression whose **Speech** is `shout`, and add a second speech box with the ID `shout` and a jagged red frame:

```dialogue
Guard: Halt. Who goes there?
Guard.angry: I said halt!
```

The first line appears in the default box. The second appears in the `shout` box, and the default box hides while it's shown. If no box has the ID the Expression names, the line falls back to the default box instead of disappearing.

How you give a speech box its ID depends on the UI option: the **ID** field of a **Speech** entry in [Unity UI](unity-ui.md#speech-boxes), or the element's name in [UI Toolkit](ui-toolkit.md#speech-boxes). The Default, Cyberpunk, and Messages samples include a second box with the ID `secondary`.

## Follow the speaker

A speech box, and the list of choices, can follow the speaker on screen, like a speech bubble over a character's head. Every frame, the interface moves the panel to where the main camera sees the speaker's **Game Object**, and keeps it inside its parent so it doesn't slide off the screen. The choice list follows the first choice whose Actor has a **Game Object**.

When there's nothing to follow, the panel returns to its place in the layout. That happens on narrator lines, for Actors without a **Game Object**, when the scene has no camera tagged `MainCamera`, and while the speaker is behind the camera.

Unity UI sets this up with a **Follow** field on each speech box, and UI Toolkit with the `gc-dialogue-speech-follow` tag. The Fantasy samples follow the speaker with both their speech bubble and their choices.

## Start from a sample

The module includes eight ready-made Skins, four for each UI option. Import them from the **Samples** tab of the Package Manager, as described in [Exploring the examples](../../index.md#exploring-the-examples). Each one contains its Skin asset, its prefabs, and any fonts, textures, and sounds it uses.

| Sample | Shows |
| :--- | :--- |
| **Default Skin** | A speech box with portraits, choices, and a choice timer. |
| **Messages Skin** | The conversation as a scrolling log of messages. |
| **Fantasy Skin** | A speech bubble and choices that follow the speaker. |
| **Cyberpunk Skin** | A futuristic layout with portraits and Actor descriptions. |

Each comes in a **(UGUI)** and a **(UI Toolkit)** version that look alike, which also makes them a useful reference when you compare the two systems. The UI Toolkit versions are styled with USS and don't include the Unity UI versions' animations.

## Where to go next

- **[Unity UI](unity-ui.md)** — build an interface with a **Dialogue UI** component.
- **[UI Toolkit](ui-toolkit.md)** — build an interface from a UXML document and USS.
- **[Compendium Actors](../compendiums.md#actors)** — set the names, portraits, colors, and Expressions the interface shows.
- **[Script choice settings](../scripts.md#choice-and-text-options)** — control timed, shuffled, and unavailable choices.
