TypewriterLabel
A TypewriterLabel is an AnimatedLabel that reveals its text: one glyph, one word or one line at a time, at a speed or at the times you give. The DialogueBox types its lines with it. Because it is an AnimatedLabel, the effect tags work in its text, and a lyric video can pop its words in on the beat and make them wave.


<UIToolbox.TypewriterLabel characters-per-second="45" />
<UIToolbox.TypewriterLabel
reveal-by="Word"
entry="Pop"
cues="0.5, 1, 1.5, 2.25"
text="Turn it <wave>up</wave>, we" />
line.Finished += ShowChoices;
line.text = "Welcome, <b>traveler</b>!"; // types from the first glyph
// shows all of it, for a key press during typing
line.Complete();
| Member | Description |
|---|---|
text |
A new text types from the first glyph. The same text again does not type again. Effect tags and rich text tags work. |
CharactersPerSecond (characters-per-second) |
The speed in characters per second (40). Zero or less shows the text at once, unless Cues give the times. |
RevealBy (reveal-by) |
The unit that appears at a time: Character (the default), Word or Line. |
Entry (entry) |
How each unit comes in: Fade (the default), Pop, Slide, Drop or None. |
EntryDuration (entry-duration) |
The time in milliseconds that a unit takes to come in. 0 (the default) is the time of one character for Fade and 300 milliseconds for Pop, Slide and Drop. |
EntryEasing (entry-easing) |
The curve of the entry. Entry sets it; set it after Entry for another curve. |
Cues (cues) |
The start time in seconds of each unit, as a comma-separated list ("0, 0.4, 0.9"). Cues replace CharactersPerSecond. |
SetCues(times) |
Sets the cues from numbers, with no text to parse. Null or an empty list types at CharactersPerSecond again. |
CueTimes |
The cue times in seconds. Empty when the label types at CharactersPerSecond. |
Elapsed |
The time of the reveal in seconds since Restart. Setting it shows the reveal at that time, forward or back, and stops the clock of the label. |
IsTyping |
True while units are still to appear or to finish their entry. |
VisibleGlyphs |
The number of glyphs that show now: the glyphs whose unit has started its entry. A space counts as a glyph, except where the line wraps; a rich text tag does not. |
Complete() |
Shows all of the text at once. |
Restart() |
Hides the text and types it again on the clock of the label. |
Finished |
Raised once when the entry of the last unit ends: after typing, after Complete, or when Elapsed passes the end. A text with nothing to type (an empty text or a speed of zero) also raises it, so a dialogue can wait for it on every line. |
The members of AnimatedLabel (Effect, Speed, Amplitude, Playing, the gradient colors) work as they do there.
Units
RevealBy sets what appears at a time.
| Value | Unit |
|---|---|
Character |
One glyph. |
Word |
One word. A space belongs to the word before it, so a word and its space appear together. |
Line |
One laid-out line. A new width that moves words to another line changes the lines. |
At a speed, the clock counts characters in each mode, spaces too, so a word or a line appears when the clock reaches its first character. A long word takes as long to come as it would take to type.
Entries
Entry sets how a unit comes in when its time comes.
| Value | Entry |
|---|---|
Fade |
The unit fades in. Over one character time, this is the soft edge of the typing. |
Pop |
The unit grows from small to its size around its center, with a small overshoot. |
Slide |
The unit slides in from the right as it fades in. |
Drop |
The unit falls into place from above as it fades in. |
None |
The unit shows at once. |
The entry moves only the glyphs. The words do not move to another line, and the label keeps its size.
Cues
Cues give each unit its own time, for words on the beat of a song or lines on the beat of a cutscene. Unit n appears at cue n:
line.RevealBy = TypewriterReveal.Word;
line.Entry = TextEntry.Pop;
line.SetCues(new[] { 0.5f, 1f, 1.5f, 2.25f, 2.75f, 3.25f });
line.text = "Turn it up, we never stop";
- A unit with no cue appears with the last cue.
- In the
cuestext, a part that is not a number takes the cue before it. - The cues do not have to be in order. A cue that is earlier than the cue before it shows its unit earlier.
SetCuescopies the times and makes no garbage once the label has held as many cues.
Elapsed and music
The label runs its own clock after Restart. To follow music, a video or a timeline, set Elapsed from that clock each frame. The label then shows the reveal at that time, forward or back, and stops its own clock:
using UIToolbox;
using UnityEngine;
using UnityEngine.UIElements;
public class LyricLine : MonoBehaviour
{
[SerializeField] private UIDocument document;
[SerializeField] private AudioSource music;
private TypewriterLabel line;
private void Start()
{
line = document.rootVisualElement.Q<TypewriterLabel>("line");
line.SetCues(new[] { 0.5f, 1f, 1.5f, 2.25f, 2.75f, 3.25f });
line.text = "Turn it up, we never stop";
music.Play();
}
// The music is the clock: a pause or a seek of the music shows in
// the words
private void Update() => line.Elapsed = music.time;
}
- A time past the end finishes the text and raises
Finished. A time before the end hides the later units again, so a scrub back works. Restartstarts the clock of the label again.- A Timeline can drive it: set
Elapsedin itsPlayheadMovedevent, and read the cues from the times of its markers.
Notes
- The label lays out the full text at once and changes the glyphs through
PostProcessTextVertices. The words do not jump to the next line while they appear, and rich text tags work. - The units are measured when the text, the layout or the reveal settings change, not each frame.
- The typing runs on the element scheduler, so it stops when the label leaves the panel.
- The typing waits while the label does not show: in a hidden tab, in a minimized or closed window, under an element with
display: none, or withvisibility: hidden. It goes on from the same moment when the label shows again, soFinishedcomes after the label shows. A label with no text to type does no work each frame. - With
opacity: 0on the label, the typing goes on and the label does not draw. A label that setsElapsedfrom its own clock follows that clock in all cases. - A label that a parent clips, or that a
ScrollViewscrolls out of view, still types and draws. On the rows that do not show, setPlaying = falseto stop the effects, and callComplete()to end the typing. - The label is one text element, so it cannot hold an icon or an input glyph. For a text with
{south}or{gold}in it, use an InlineIconLabel. It does not type.
In the examples


Styling
| Class | Element |
|---|---|
tb-typewriter-label |
The label: --tb-color-text, and the text wraps. The hidden glyphs are transparent; they take no style. |
tb-typewriter-label--typing |
On the label while units are still to appear. |
The TypewriterLabelDemo scene shows the dialogue box of a game, where a click completes the line and the next click shows the next line, the terminal of a sci-fi game that types its lines one after the other, a quest letter that gets its seal when the last glyph shows, the looks of the label, and a lyric video. In the lyric video a Timeline drives the words, the effects and the camera, and a drag of a word marker moves the cue of its word.
The DirectorDemo scene types the captions of a video. The controller sets Elapsed from the video time, so a pause or a seek of the video shows in the caption. See Video director.