[HOWTO] How To: Change Subtitle Bubble Image

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Tony Li
Posts: 22695
Joined: Thu Jul 18, 2013 1:27 pm

[HOWTO] How To: Change Subtitle Bubble Image

Post by Tony Li »

This article explains one way to change an actor's overhead subtitle bubble panel during a conversation.

1. Set up an overhead bubble panel: How To: Show Overhead Conversation Bubble Text. Add the bubble panel as an instance (child) of the actor.

2. Add additional bubble subtitle panels to your actor's GameObject -- for example, with different bubble images for different emotions.

3. Add this script to your actor:

Code: Select all

using PixelCrushers.DialogueSystem;
using UnityEngine;

namespace Gameplay
{
    public class SetBubblePanel : MonoBehaviour
    {
        [SerializeField] private StandardUISubtitlePanel[] _bubblePanels;

        void OnConversationLine(Subtitle subtitle)
        {
            if (subtitle == null) return;
            if (subtitle.speakerInfo.transform == this.transform)
            {
                int index = Field.LookupInt(subtitle.dialogueEntry.fields, "Bubble");
                if (0 <= index && index < _bubblePanels.Length)
                {
                    DialogueManager.standardDialogueUI.ForceOverrideSubtitlePanel(_bubblePanels[index]);
                }
            }
            else
            {
                DialogueManager.standardDialogueUI.ForceOverrideSubtitlePanel(null);
            }
        }
    }
}
4. Add the script to your actor. Assign the bubble panels, including the original one, to the Bubble Panels list. The original should be element 0.

5. Add a custom Number field "Bubble" to your dialogue entries. When you want to use a different bubble, set the Bubble field to the element number in the script's Bubble Panels list.

Example scene (including script above):

DS_ChangeBubbleImageExample_2024-11-29.unitypackage
Post Reply