Forum rules - please read before posting.

Custom use of speech color in Subtitles UI

I'm trying to use the characters' speech color to paint the background of the text panel, instead of the text itself.

I tried putting this in a public method

GameObject.Find("SubtitlesPanel").GetComponent<RawImage>().color = AC.KickStarter.dialog.GetSpeakingCharacter().speechColor;

and then calling the method via an ActionList whenever the subtitles panel was turned on.

It seemed straightforward enough, but sadly, it didn't work as expected. The background color remained unchanged while the text was displaying. BUT the correct color flashed for a moment just before the subtitle was gone.

I have crafted a few semi-working solutions, but none of them feels right, so I thought I'd ask for your help to figure this out.

Thanks in advance :)

Comments

  • edited April 2020

    At what moment are you changing the colour? Once the Speech Action has completed?

    A better way to do this would be to hook into the OnStartSpeech event, which is triggered every time a speech line begins - and includes a parameter to get the speaking character:

    using UnityEngine;
    using AC;
    
    public class SetSubtitleBGColour : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnStartSpeech += StartSpeech; }
    
        private void OnDisable () { EventManager.OnStartSpeech -= StartSpeech; }
    
        private void StartSpeech (AC.Char character, string lineText, int lineID)
        {
            if (character != null)
            {
                GameObject.Find("SubtitlesPanel").GetComponent<UnityEngine.UI.RawImage>().color = character.speechColor;
            }
        }
    
    }
    

    For more on custom events, see this tutorial.

  • At first glance this seems to be working, with the following two remarks (for anyone wanting to do the same) :
    1. GameObject.Find returns null, so I had to use a public variable and assign the RawImage via the Inspector.
    2. The "duplicate for each line" option must be disabled in the Menu Manager.

    I'll put it to more tests later and let you know if I find anything unusual.

    Thanks :)

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.