Forum rules - please read before posting.

Changing manager during gameplay?

Hi, loving the asset so far but there's something I can't figure out. I want my Narration text and Subtitle speech text to scroll at different speeds and also use different spacing rules, I want the Narration to be spaced properly and be one wall of text, whereas I want the Speech Subtitles to move onto the next dialogue after each line, with the "Treat carriage returns as separate speech lines?" option ticked.

So for example I want the Narration:

Hi, this is example Narration.

Left click to continue.

To be one page


Whereas I want this example:

"Hi, my name is Jim."

"How are you today?"

To show the first line as dialogue, and then after that, the second line as dialogue (Via the ""Treat carriage returns as separate speech lines?" setting)

Is there a way to do this? The fields "Text scroll speed" and "Treat carriage returns as separate speech lines?" affects both, so I was thinking I could create a second manager with different settings, and change that during gameplay. Is this possible to do?

Thanks for any help! :)

Comments

  • Changing Manager asset at runtime should generally be avoided except for very specialised situations, as the data they contain is closely linked to the game. The Speech Manager, for example, also contains data related to languages, speech audio etc.

    What you can do, however, is change Manager field values at runtime through scripting.

    To modify any Manager field, right-click that field's label to copy an API reference to it, which can then be used in a script. In the case of the text scroll speed and "Treat carriage returns.." options, these are:

    AC.KickStarter.speechManager.textScrollSpeed
    AC.KickStarter.speechManager.separateLines
    

    The easiest way to modify such fields is to do so using a custom event, which is a way of hooking up custom code to common tasks. In this case, you could use the OnStartSpeech_Alt event to change the speed based on whether or not a speech line has a speaking character or not:

    using UnityEngine;
    using AC;
    
    public class SpeechEventExample : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnStartSpeech_Alt += OnStartSpeech; }
        private void OnDisable () { EventManager.OnStartSpeech_Alt -= OnStartSpeech; }
    
        private void OnStartSpeech (Speech speech)
        {
            if (speech.GetSpeakingCharacter () == null)
            {
                // Narration
                KickStarter.speechManager.textScrollSpeed = 50f;
            }
            else
            {
                // Speech
                KickStarter.speechManager.textScrollSpeed = 30f;
            }
        }
    
    }
    

    Changing the "Treat carriage returns.." option is a little more tricky, as this needs to be changed before the speech (and associated event) is triggered.

    If you're looking to have the "Left click to continue." text to appear for all narration lines, though, it's possible to automate this through events as well. This second example also adds this text to any narration lines:

    using UnityEngine;
    using AC;
    
    public class SpeechEventExample : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnStartSpeech_Alt += OnStartSpeech; }
        private void OnDisable () { EventManager.OnStartSpeech_Alt -= OnStartSpeech; }
    
        private void OnStartSpeech (Speech speech)
        {
            if (speech.GetSpeakingCharacter () == null)
            {
                // Narration
                KickStarter.speechManager.textScrollSpeed = 50f;
                speech.ReplaceDisplayText (speech.FullText + "\nLeft click to continue.");
            }
            else
            {
                // Speech
                KickStarter.speechManager.textScrollSpeed = 30f;
            }
        }
    
    }
    
  • Thanks so much for the in depth response. I'm using the first script and it works great, exactly what I was hoping for. In regards to the second one, I was just hoping there would be an easy way in the editor that I was missing, but I'll just disable the "Treat carriage returns.." option and break the dialogue into chunks, that works well enough. :smile:

    It feels incredible getting such fast and helpful support from the developer, quality product and custom service Chris. 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.