Immerse SDK
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Subtitles

The subtitle view prefabs are intended to be used to display subtitle text during audio or video playback. Two main variants of the subtitle view are available, each with their own TextMeshPro versions.

Screen Space

This prefab is intended for non-XR applications where you simply want to display subtitle text at the bottom of the screen.

World Space

This prefab is intended for XR applications where the subtitle display needs to be in the world with the user. By default this prefab includes a CanvasCameraFollower component so that the subtitle text will follow the XR user’s head, giving them a screen-space-like experience. If the CanvasCameraFollower component is removed from the prefab, it will remain in place, which is ideal for placing in a static location along side a VideoPlayer.

Timelines

The subtitle feature is compatible with Unity’s Timelines feature. This allows for the creation of a subtitle asset that can be dragged onto a timeline for easy synchronization with other tracks such as AudioClips.

Subtitle assets can either be created manually inside Unity by entering the start/end times for each text block and the text value, or by importing an SRT file into the project.

Timeline with synced audio and subtitle tracks

Manual Display

The SubtitleView class contains two public methods. One to show text and one to hide the display. By utilizing these methods, it is very easy to have complete control over the text that is displayed by the view. See below for a very basic example that demonstrates how to use this feature.

using ImmerseSDK.UI.Subtitles;
using UnityEngine;

/// <summary>
/// Displays two buttons using Unity's legacy GUI system to show/clear subtitle text
/// </summary>
public class ManualSubtitleExample : MonoBehaviour
{
    [SerializeField]
    [Tooltip("Text to be displayed when 'Show Text' is clicked")]
    private string _text = "Hello world!";

    [SerializeField]
    [Tooltip("Subtitle view to display text")]
    private SubtitleView _view;

    private void OnGUI()
    {
        if (GUILayout.Button("Show Text"))
        {
            // Display the value of _text in our subtitle view
            _view.SetText(_text);
        }

        if (GUILayout.Button("Clear"))
        {
            // Clear the subtitle view
            _view.Clear();
        }
    }
}