Narration System

The Narration (dialogue) System allows you to define simple dialogues with subtitles that appear at the bottom of the screen, as you have seen in many other games.

This system is not a complete dialogue solution where you can talk to NPCs etc., but a system that allows you to display subtitles for dialogue at certain moments.

Adding New Dialogues

  1. Right-click on any project folder and select Create -> UHFPS -> Dialogue -> Dialogue Asset.

  2. To add a new dialogue, click the Add Dialogue button and select the Dialogue 0.

  1. Assign a Dialogue Audio, this can be any audio that contains speech and for which you want to create subtitles.

  2. You can select the type of subtitles the dialogue contains. You can select Single or Multiple.

Single: Select this type if the dialogue audio contains only one sentence or word.

Multiple: Select this type if the dialogue audio contains many different sentences or pauses.

If you have selected the option Multiple, you will have different options. For example, instead of having subtitle settings, you'll see an audio waveform where you can place subtitles at different points in the audio.

  1. Click the Add Subtitle button. This will create a new subtitle point that will be added to the start of the audio.

You can move the subtitle by dragging the vertical white line to where you want the subtitle to appear.

To select the subtitle click on the button below the vertical line.

  1. If you select subtitles, you can define subtitle settings such as who is speaking, the color of the narrator or the subtitle text.

When defining multiple subtitles, make sure that the index displayed in the button below the vertical line is in ascending order. Subtitles are stored in an array, so it is important to add subtitles in order.

This is how it should look like:

  1. To trigger a dialogue, create a new trigger object by enabling the Is Trigger option in the collider and add a Dialogue Trigger component to it.

In the component window you have several settings. The Trigger Type defines how you want the dialogue to be triggered. By a Trigger, Interaction, or by Event.

The Dialogue Type defines where the dialogue audio will be played. Type Local means that the dialogue will be played locally as an NPC narration. Type Global means that the dialogue will most likely be played by the player.

Dialogue Continue specifies how multiple dialogues will be treated. If you keep this in Sequence, the dialogues will be played one by one. If you set this to Event, the next dialogue will be played when you call DialogueSystem.NextDialogue().

DialogueSystem is a component that is added to the GAMEMANAGER object and it is Singleton so you can make easy calls.

Dialogue Binder

Dialogue Binder is a special feature that can be used in different ways. It can be used to display the current subtitle in world space or even to synchronize the NPC's mouth with the words.

Dialogue Binder works by triggering certain events that are sent by the Dialogue System, so you can create custom things simply by registering the events you need.

  1. To use the binder, add a Dialogue Binder component to your object.

  2. To use binder events, you can create a new script that will have methods with the parameters specified in the event.

Here are the methods used to display the speech bubble dialogue:

// will be called when the dialogue starts
public void OnDialogueStart(AudioSource _, string binderName)
{
    if(isPlaying = binderName == BinderName)
        TextMesh.gameObject.SetActive(true);
}

// will be called at every subtitle
public void OnSubtitle(AudioClip _, string subtitleText)
{
    if (!isPlaying)
        return;

    TextMesh.text = subtitleText;
}

// will be called at the end of the subtitle sequence
public void OnSubtitleFinish()
{
    if (!isPlaying || !HideBetweenSubtitles)
        return;

    TextMesh.text = "";
}

// will be called when the dialogue ends
public void OnDialogueEnd()
{
    if (!isPlaying)
        return;

    TextMesh.gameObject.SetActive(false);
    TextMesh.text = "";
    isPlaying = false;
}

The events will be invoked in each Dialogue Binder component, so you need to check if the binderName is the one you want to use in the script.

  1. Then you can register dialogue binder events on these methods

  1. The Binder Name can be specified in the Dialogue Trigger component.

Last updated