Captions UI

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Albyd
Posts: 20
Joined: Thu Jul 21, 2022 4:46 pm

Captions UI

Post by Albyd »

Hi there!
I was wondering if was possible to create captions for Dialogues.
I would like deaf people to be able to turn on/off an alternative dialogue UI that describes sounds they can't hear.
I was thinking to maybe use the "Menu text" field to describe sounds, but I'm not sure it would work.
Is there a way to do so?

Many thanks
User avatar
Tony Li
Posts: 20764
Joined: Thu Jul 18, 2013 1:27 pm

Re: Captions UI

Post by Tony Li »

Hi,

You can add custom fields to your dialogue entry template. (See Templates.) For example, say you've added a Text field named "Caption" to your dialogue entry template, and you've set some dialogue entries' Captions to include text like "[birds chirping]" or "[jackhammer sounds]". Then you can add a script with an OnConversationLine(Subtitle) method to your Dialogue Manager or dialogue UI (assuming the dialogue UI ends up in the Dialogue Manager's hierarchy) that does something like this:

Code: Select all

public class Captions : MonoBehaviour
{
    public bool showCaptions; // If true, show captions.
    public UITextField captionText; // Assign Text or TextMeshProUGUI component in inspector.
    
    void OnConversationLine(Subtitle subtitle)
    {
        string caption = Field.LookupValue(subtitle.dialogueEntry.fields, "Caption");
        captionText.gameObject.SetActive(showCaptions && !string.IsNullOrEmpty(caption));
        captionText.text = caption;
    }
}
Albyd
Posts: 20
Joined: Thu Jul 21, 2022 4:46 pm

Re: Captions UI

Post by Albyd »

Alright, I'm trying to make it work.
I've added the custom field to the Dialogues and attached the script to the UI I'm using, I've also assigned the subtitle text I'm working on in the PC Subtitle Panel.
However, it's giving me the following error:

NullReferenceException: Object reference not set to an instance of an object
Captions.OnConversationLine (PixelCrushers.DialogueSystem.Subtitle subtitle) (at Assets/Captions.cs:15)

Additionally, the UI is not showing.

Here are some screenshots.
Thanks for the amazing help by the way.
Attachments
Screenshot_3_UI.png
Screenshot_3_UI.png (46.55 KiB) Viewed 53 times
screenshot_2_UI.png
screenshot_2_UI.png (451.66 KiB) Viewed 53 times
Screenshot_1_UI.png
Screenshot_1_UI.png (375.34 KiB) Viewed 53 times
User avatar
Tony Li
Posts: 20764
Joined: Thu Jul 18, 2013 1:27 pm

Re: Captions UI

Post by Tony Li »

Hi,

That error suggests that a UI text component is no longer assigned to captionText.

Is there more than one instance of the Captions script in your scene?

If you enter play mode and start the conversation, is the Captions script's Caption Text field still assigned?
Albyd
Posts: 20
Joined: Thu Jul 21, 2022 4:46 pm

Re: Captions UI

Post by Albyd »

Hi Tony,
You were right, i had a duplicate, now the error has vanished.
However, the UI it's still not showing.
I'm using the default PC Subtitle Panel, which turns off automatically whenever i start a dialogue.
What do you suggest?

Thanks again
User avatar
Tony Li
Posts: 20764
Joined: Thu Jul 18, 2013 1:27 pm

Re: Captions UI

Post by Tony Li »

Create your own Text or TextMeshProUGUI component and assign it to Caption Text. Don't use the Subtitle Text GameObject, since that's for the subtitle panel's use.
Post Reply