Forum rules - please read before posting.

Link dialogue string variable to audio file

Hello, this might be a bit of an edge case, but basically I have Dialogue - Play Speech actions within external action lists that use string variable as parameters for their Line Texts. The issue is that while text typed within this field can be gathered with other Speech texts at the bottom of the Speech Manager and have an audio file path assigned, variables don't have that audio path.

For the moment I can totally make do with that and just use the Sound - Play One Shot action to play audio clips (which can be Unity Object parameters), but I wanted to ask if this feature request could be accepted in the future, and if there were any pieces of advice to achieve that myself in a convenient way ? Thanks.

Comments

  • Speech audio/lipsync data etc has to be associated with a speech line. You can't use a String parameter, because its usage isn't strictly limited to speech text.

    What you can do, however, is create an ActionList that basically has all your speech lines in one. This list wouldn't be run directly, but it would be included in the "Gather text" process so that each line can be given audio etc.

    Instead of a String parameter, you can then switch to an Integer that represents the intended line's ID number. Using this Action on the wiki, you can then rely on that ID to play the associated speech:

    https://adventure-creator.fandom.com/wiki/Playing_speech_from_ID

  • edited August 15

    Hi, thank you so much for this answer ! I just have to disagree with how the ActionSpeechID sets the runtimeSpeaker to null and instead either gets the player or uses GetCharacterWithName - this only works if we've got one specific character with a unique name, not if we have duplicates of the same character, like a generic enemy for example.

    Here's how I fixed it by commenting some stuff out in Assign Values and pasting in some stuff from the original ActionSpeech :

    public override void AssignValues(List<ActionParameter> parameters)
    {
        speech = null;
        //runtimeSpeaker = null;
    
        if (parameters != null) ownParameters = parameters;
    
        sharedLineID = AssignInteger(parameters, sharedLineParameterID, sharedLineID);
    
        sharedSpeechLine = KickStarter.speechManager.GetLine(sharedLineID);
        if (sharedSpeechLine != null)
        {
            messageText = KickStarter.runtimeLanguages.GetTranslation(sharedSpeechLine.text, sharedLineID, Options.GetLanguage());
            lineID = sharedLineID;
    
            //if (sharedSpeechLine.isPlayer)
            //{
            //    runtimeSpeaker = KickStarter.player;
            //}
            //else
            //{
            //    runtimeSpeaker = GetCharacterWithName(sharedSpeechLine.owner);
            //}
        }
    
        if (isPlayer)
        {
            runtimeSpeaker = AssignPlayer(playerID, parameters, parameterID);
        }
        else
        {
            runtimeSpeaker = AssignFile<Char>(parameters, parameterID, constantID, speaker);
            if (runtimeSpeaker == null && speaker == null && constantID != 0 && parameterID < 0)
            {
                LogWarning("Cannot find speaker with Constant ID = " + constantID);
            }
        }
    
    }
    
    

    I also pasted that into ShowGUI :

                if (Application.isPlaying && runtimeSpeaker == null)
                {
                    if (isPlayer)
                    {
                        runtimeSpeaker = AssignPlayer(playerID, parameters, parameterID);
                    }
                    else
                    {
                        runtimeSpeaker = AssignFile<Char>(parameters, parameterID, constantID, speaker);
                    }
                }
    
                isPlayer = EditorGUILayout.Toggle("Player line?", isPlayer);
                if (isPlayer)
                {
                    PlayerField(ref playerID, parameters, ref parameterID);
                }
                else
                {
                    if (Application.isPlaying)
                    {
                        if (runtimeSpeaker)
                        {
                            EditorGUILayout.LabelField("Speaker: " + runtimeSpeaker.name);
                        }
                        else
                        {
                            EditorGUILayout.HelpBox("The speaker cannot be assigned while the game is running.", MessageType.Info);
                        }
                    }
                    else
                    {
                        ComponentField("Speaker:", ref speaker, ref constantID, parameters, ref parameterID);
                    }
                }
    

    I hope this change can be applied to the script on the wiki, I do think it would be justified.

    In any case, thanks again as I was able to make it work with your direction ! I also thought it was about time I wrote a well deserved 5 star review on the UAS ;)
    https://assetstore.unity.com/packages/tools/game-toolkits/adventure-creator-11896#reviews

  • Very much appreciated, thank you.

    Re the script: for the widest range of uses, a hybrid is probably best - where you can optionally assign a character, but otherwise it relies on the original name. I'll take a look, thanks for the feedback.

  • Done. You can now either rely on the original speaker by name, or assign an optional override.

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.