Options Presenter

The Options Presenter (Yarn 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 followed Adding Presenters, you already have one.

Where the buttons go

The Options Presenter needs two things: a Widget Blueprint to make each button from, and a panel in your dialogue widget to put the buttons in.

Each time the dialogue reaches some options, the Options Presenter makes a widget for each one from Option Widget Class, and adds it to Options Container. Once the player has picked, the buttons are hidden, and they’re reused for the next set of options. Leave the container empty in the Designer.

To set it up:

  1. Make a Widget Blueprint for the buttons, as described in Making the option widget, and set the Options Presenter’s Option Widget Class to it in the Details panel, under Yarn Spinner > Widgets.
  2. In your dialogue widget, such as the WBP_Dialogue from the Line Presenter page, add an empty Vertical Box named OptionsBox, and turn on Is Variable. To fade the options in and out, put it inside another panel, such as a Border named OptionsPanel, and turn on Is Variable for that too.
  3. In the Actor’s Begin Play, after creating the widget, add Set Options Container and Set Fade Widget nodes on the YarnOptionsPresenter, and connect them to OptionsBox and OptionsPanel.
The Begin Play from the Line Presenter page, with the Options Presenter’s Options Container and Fade Widget set before the dialogue starts.

Like the Line Presenter’s widgets, Options Container and Fade Widget aren’t in the Details panel, because your widgets only exist once the game is running. In C++, set them in the same place as the Line Presenter’s widgets in ADialogueActor::BeginPlay(), before StartDialogue():

OptionsPresenter->OptionsContainer = Cast<UPanelWidget>(Widget->GetWidgetFromName(TEXT("OptionsBox")));
OptionsPresenter->FadeWidget = Widget->GetWidgetFromName(TEXT("OptionsPanel"));
Connecting the Options Presenter to the widgets, in ADialogueActor::BeginPlay().

UPanelWidget needs #include "Components/PanelWidget.h".

If Option Widget Class or Options Container isn’t set when options arrive, the Options Presenter logs an error and the dialogue carries on after the options, as if none had been picked.

The Options Presenter hides Options Container when the dialogue starts, and shows it when options arrive, so there’s no need to hide it yourself once the dialogue is running.

Making the option widget

Each button is a Widget Blueprint whose parent class is Yarn Option Widget:

  1. In the Content Browser, choose AddUser InterfaceWidget Blueprint. In the dialog that opens, expand All Classes, search for Yarn Option Widget, and select it. Name it WBP_Option.
  2. Open it, and in the Designer, add a Button named OptionButton, with a Text Block (Text in the Palette) named OptionText inside it.
  3. Style the button and text however you like.
  4. Set the Options Presenter’s Option Widget Class to WBP_Option.

The names matter. Yarn Option Widget looks for a Button named OptionButton and a Text Block named OptionText, and the Widget Blueprint doesn’t compile without them.

WBP_Option in the Designer. The Hierarchy shows OptionButton containing OptionText, and the canvas shows the button as a wide bar with the text I'm here about the lamp.
WBP_Option, a button with a Text Block inside it.

By default, Yarn Option Widget puts the option’s text in OptionText, turns off OptionButton when the option is unavailable, and tells the Options Presenter when the player clicks the button. The option’s text never includes the character’s name.

To change how the button looks as it’s highlighted, or when it’s unavailable, override these events in WBP_Option, from Functions > Override in the My Blueprint panel:

EventWhen it’s called
Setup OptionThe button is about to show an option. Passes the option and its index. By default, sets the text and turns the button on or off.
Set Option UnavailableThe option can’t be chosen. By default, turns the button off.
On Option SelectedThe option has been highlighted, by the keyboard or when the options appear. By default, gives the button keyboard focus.
On Option DeselectedThe option is no longer highlighted.
The events you can override in Yarn Option Widget.

To keep the default behaviour, add a call to the parent function, such as Parent: Setup Option, in your override. Your Blueprint can also read Option Index, Is Available and Is Selected.

In C++, make a subclass of UYarnOptionWidget, and make your Widget Blueprint’s parent class that subclass. This one colours the highlighted option’s text:

#pragma once

#include "CoreMinimal.h"
#include "YarnOptionsPresenter.h"
#include "HighlightOptionWidget.generated.h"

UCLASS()
class UHighlightOptionWidget : public UYarnOptionWidget
{
	GENERATED_BODY()

public:
	UPROPERTY(EditAnywhere)
	FLinearColor HighlightColor = FLinearColor(1.0f, 0.8f, 0.3f, 1.0f);

	virtual void OnOptionSelected_Implementation() override
	{
		Super::OnOptionSelected_Implementation();
		OptionText->SetColorAndOpacity(FSlateColor(HighlightColor));
	}

	virtual void OnOptionDeselected_Implementation() override
	{
		Super::OnOptionDeselected_Implementation();
		OptionText->SetColorAndOpacity(FSlateColor(FLinearColor::White));
	}
};
Line 4 UYarnOptionWidget is declared in YarnOptionsPresenter.h.
Lines 13–14 The colour for the highlighted option. Change it in the Widget Blueprint’s Class Defaults.
Lines 16–20 Keep the default behaviour, which gives the button keyboard focus, then colour the text.
Lines 22–26 Put the colour back when the highlight moves to another option.
An option widget that colours the highlighted option.

Picking an option

When the options appear, the first one the player can choose is highlighted. The player can:

  • click an option,
  • move between options with Navigate Up Key and Navigate Down Key, Up and Down by default, or W and S, and choose the highlighted one with Confirm Key, Enter by default, or Space Bar.

The highlight wraps around from the last option to the first, and skips options the player can’t choose. The keys are read from the first Player Controller, and only while the options are fully faded in. Each key setting can be any key Unreal knows, including gamepad buttons. Turn off Enable Keyboard Navigation to use only the mouse.

Use Fade Effect, under Fade, fades the options in when they appear and out once the player has picked. It’s on by default, but it only works when Fade Widget is set. Fade In Duration and Fade Out Duration set how long each fade takes, in seconds. The Line Advancer’s Option Hurry Up Key skips the fade in. See Line Advancer.

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, under Behaviour, to show them as buttons that can’t be pressed.

Strikethrough Unavailable, which is on by default, wraps the text of an unavailable option in <s> and </s>. A plain Text Block shows these tags as they are, so turn Strikethrough Unavailable off unless your option widget’s Setup Option handles them.

If every option is unavailable, the Options Presenter shows nothing, logs a warning, and the dialogue carries on after the options, as if none had been picked. This happens whatever the Dialogue Runner’s Allow Option Fallthrough is set to. See Options.

Showing the last line

The Line Presenter leaves the last line on screen while options are showing. To show it somewhere else as well, such as above the options in their own panel, turn on Show Last Line, under Last Line, and give the Options Presenter a Text Block for it.

The Last Line settings appear in the Details panel, but like the other widget settings, you set them from Blueprints or C++ while the game runs:

  • Last Line Text Widget is the Text Block for the last line’s text.
  • Last Line Container is shown when there’s a last line to show.
  • Last Line Character Name Widget is the Text Block for the speaker’s name.
  • Last Line Character Name Container is hidden when the last line has no speaker.

The speaker’s name only appears in its own Text Block when you set both Last Line Character Name Widget and Last Line Character Name Container. If you don’t set Last Line Character Name Widget, the name stays at the start of the last line’s text, like Rosa: Are you here about the lighthouse?.

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. See Building Your Own Presenter.

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.

Events and functions

EventWhen it’s called
On Option Selected BPThe player picked an option, before the options fade out. Passes Option Index, the option’s position in your Yarn Script, starting at 0.
On Options Display CompleteThe options have appeared, after any fade in.
On Options DismissedThe options have gone, after any fade out, and when the dialogue ends.
The Options Presenter’s events.

To build your own controls for picking options, call these functions on the Options Presenter:

FunctionWhat it does
Select Next OptionMoves the highlight to the next option the player can choose.
Select Previous OptionMoves the highlight to the previous option the player can choose.
Select Option by IndexMoves the highlight to the option at Option Index.
Confirm Selected OptionPicks the highlighted option.
Get Selected Option IndexThe index of the highlighted option, or -1 if there isn’t one.
Are Options VisibleTrue while options are on screen and can be picked.
The Options Presenter’s functions.

Settings

The Options Presenter's Yarn Spinner settings, with Option Widget Class set to WBP_Option, and the Behaviour, Last Line, Fade and Keyboard sections collapsed.
An Options Presenter with WBP_Option as its Option Widget Class.
SettingDefaultWhat it does
Option Widget ClassnoneThe Widget Blueprint each button is made from. Its parent class has to be Yarn Option Widget.
Options ContainernoneThe panel the buttons are added to. Set it while the game runs.
Fade WidgetnoneThe widget that’s faded in and out. Set it while the game runs.
Show Unavailable OptionsOffShows options the player can’t choose, as buttons that can’t be pressed.
Strikethrough UnavailableOnWraps the text of unavailable options in <s> tags. Only editable when Show Unavailable Options is on.
Show Last LineOffShows the line before the options.
Last Line Text WidgetnoneThe Text Block for the last line’s text.
Last Line ContainernoneShown when there’s a last line to show.
Last Line Character Name WidgetnoneThe Text Block for the last line’s speaker.
Last Line Character Name ContainernoneHidden when the last line has no speaker.
Use Fade EffectOnFades Fade Widget in and out.
Fade In Duration0.25Seconds to fade in.
Fade Out Duration0.1Seconds to fade out.
Enable Keyboard NavigationOnLets the player highlight and pick options with keys.
Navigate Up KeyUpHighlights the previous option.
Navigate Up Key AltWA second key that does the same.
Navigate Down KeyDownHighlights the next option.
Navigate Down Key AltSA second key that does the same.
Confirm KeyEnterPicks the highlighted option.
Confirm Key AltSpace BarA second key that does the same.
Every Options Presenter setting.

The Details panel also shows the Auto Advance section every Presenter has. The Options Presenter doesn’t use it.

Next step Typewriter and Effects Changing how text appears, and the widget effects for fades, shakes and punches.