Options Presenter

The Options Presenter shows your options as buttons. When the player picks one, it tells the Dialogue Runner which option was picked, and the dialogue carries on from there.

If you added the Dialogue System prefab in Adding Presenters, you already have one.

Where the buttons go

The Options Presenter adds its buttons as children of the GameObject with its Canvas Group. In the Dialogue System prefab, that’s the Options Presenter’s own GameObject:

Dialogue System Dialogue RunnerIn Memory Variable Storage
Canvas CanvasCanvas ScalerGraphic Raycaster
Options Presenter Vertical Layout GroupContent Size FitterCanvas GroupOptions Presenter
Background ImageLayout Element
Last Line TextMeshPro - Text (UI)
The Options Presenter in the Dialogue System prefab.

Each time the dialogue reaches some options, the Options Presenter makes a button for each one from Option View Prefab, and adds it after the GameObject’s other children. The Vertical Layout Group stacks the buttons under Last Line. Once the player has picked, the buttons are turned off, and they’re reused for the next set of options.

If Canvas Group is empty, the buttons are added under the Options Presenter’s own GameObject, and the options don’t fade in or out.

The Options Presenter hides itself when the scene starts, by setting the Canvas Group’s Alpha to 0 and turning off Interactable and Blocks Raycasts, so there’s no need to hide it yourself.

Picking an option

When the options appear, the first one on screen is selected. The player can:

  • click an option,
  • move between options with the arrow keys or a gamepad, and choose one with the Event System’s submit input, such as Enter.

Hovering the mouse over an option also selects it. In the default Option Item prefab, the selected option is white with a dot beside it, and the others are grey.

An Options Presenter over a 3D scene, showing the last line, Is there anything people are interested in?, above five options. The first option, Tell us about the basic samples, is white with a dot beside it, and the other four are grey
Options in the Welcome sample. The first option is selected, and the last line is shown above them.

Picking options uses Unity’s UI system, so your scene needs an Event System. The Dialogue System prefab has one.

Fade UI, under Fade, fades the options in when they appear and out once the player has picked. It’s on by default. Fade Up Duration and Fade Down Duration set how long each fade takes, in seconds. The Line Advancer’s Hurry Up Options input skips the fade in. See Line Advancer.

When Canvas Group is set, the fade in is the only thing that makes the options visible. If you turn off Fade UI, the buttons are still there and can be clicked, but the player can’t see them. To show the options without a fade, leave Fade UI on and set Fade Up Duration to 0.

Options the player can’t choose

An option with a condition is unavailable when the condition is false. In this example, the second option is only available if $has_key is true:

Rosa: Are you here about the lighthouse?
-> Yes. I heard the lamp went out.
-> I can open the door for you. <<if $has_key>>
-> No, I'm just passing through.
The second option is only available when $has_key is true.

By default, the Options Presenter doesn’t show unavailable options at all. Turn on Show Unavailable Options to show them as buttons that can’t be pressed. In the default Option Item prefab, they’re faded, with a line through the text.

If every option is unavailable, the Options Presenter shows nothing. What happens next depends on the Dialogue Runner’s Allow Option Fallthrough setting. See Options.

Changing how the buttons look

The Options Presenter makes each button from the prefab in Option View Prefab. By default that’s the Option Item prefab, in PackagesYarn SpinnerPrefabs:

Option Item TextMeshPro - Text (UI)Option Item
Option Background Image
Selection Indicator Image
The default Option Item prefab.

To change how the buttons look, make your own prefab and assign it to Option View Prefab. Don’t edit the default prefab: it’s part of the package, and updating the package replaces it.

Start by duplicating Option Item into your own project’s Assets folder and changing the copy. The root of the prefab needs an Option Item component, which has these settings:

SettingWhat it does
TextThe text field for the option’s text. It has to be set.
Selection ImageAn Image that shows the current appearance’s sprite and colour. It’s hidden when that appearance has no sprite.
NormalThe sprite and colour for an option that isn’t selected.
SelectedThe sprite and colour for the selected option.
DisabledThe sprite and colour for an unavailable option.
Disabled Strike ThroughDraws a line through the text of unavailable options.
The settings of the Option Item component.

The colour of each appearance is used for both the text and Selection Image. In the default prefab, Selection Image is Selection Indicator, and only Selected has a sprite, so the dot only appears beside the selected option.

Option Item is a Unity UI Selectable, so it also has the usual Interactable, Transition and Navigation settings. In the default prefab, Navigation is Vertical, with Wrap Around on, so pressing down on the last option moves to the first.

The option’s text never includes the character’s name.

Showing the last line

When options appear, the line before them usually disappears. To keep it on screen above the options, turn on Shows Last Line and assign a text field to Last Line Text. The Dialogue System prefab already does this, with its Last Line text field.

These settings appear under Shows Last Line once it’s on:

  • Last Line Text is the text field for the last line’s text. It has to be set when Shows Last Line is on.
  • Last Line Container is hidden when there’s no last line to show. If you leave it empty, the Last Line Text’s own GameObject is used.
  • Last Line Character Name Text is the text field for the speaker’s name.
  • Last Line Character Name Container is hidden when the last line has no speaker. If you leave it empty, the Last Line Character Name Text’s own GameObject is used.

If you don’t set Last Line Character Name Text, the speaker’s name is left off.

Shortening the last line

A long line can take up too much space above the options. Put [lastline/] in the line where you want the shortened version to start:

Rosa: I've been keeping this light for thirty years, and I've never once let it go out. [lastline/]So, will you help me fix it?
-> Yes.
-> No.
A long line, shortened above the options with [lastline/].

The Line Presenter shows the whole line. Above the options, the Options Presenter shows only what comes after [lastline/], with “…” in front: “…So, will you help me fix it?”

Time limits

The Options Presenter waits until the player picks an option. To give the player a limited time to choose, you need a Presenter of your own. The Options That Timeout sample has one.

To show the option the player picked as a line of dialogue, turn on Run Selected Option As Line on the Dialogue Runner. See Options.

Settings

The Inspector for the Dialogue System prefab's Options Presenter, showing Canvas Group set to Options Presenter, Option View Prefab set to Option Item, Shows Last Line turned on with Last Line Text set to Last Line and Last Line Container, Last Line Character Name Text and Last Line Character Name Container empty, Show Unavailable Options turned off, and a Fade group with Fade UI turned on, Fade Up Duration 0.25 and Fade Down Duration 0.1
The Options Presenter in the Inspector.
SettingDefaultWhat it does
Canvas GroupnoneThe Canvas Group that’s faded in and out. The buttons are added under its GameObject.
Option View PrefabnoneThe prefab each button is made from. The Dialogue System prefab uses Option Item.
Shows Last LineOffShows the line before the options above them. The Dialogue System prefab turns it on.
Last Line TextnoneThe text field for the last line’s text.
Last Line Containerthe last line textHidden when there’s no last line to show.
Last Line Character Name TextnoneThe text field for the last line’s speaker.
Last Line Character Name Containerthe character name textHidden when the last line has no speaker.
Show Unavailable OptionsOffShows options the player can’t choose, as buttons that can’t be pressed.
Fade UIOnFades the options in and out. When Canvas Group is set, turning this off leaves the options invisible.
Fade Up Duration0.25Seconds to fade in. Only shown when Fade UI is on.
Fade Down Duration0.1Seconds to fade out. Only shown when Fade UI is on.
Every Options Presenter setting.
Next step Typewriter and Effects Changing how text appears, and writing your own typewriter.