Forum rules - please read before posting.

Simple switching of character talk animations in dialogue action?

Hi!

I'm trying to figure out the most efficient way to be able to set specific character talk animations in action lists. I know the 'character:animate > set standard' action exists, but I was wondering if there might be a way to edit the dialogue action to add a kind of dropdown of the various talking animations you have set up for each character's animator? Like:

  • Dialogue: Play speech
  • [Speaker]
  • Talk Animation [dropdown list] (CharacterAngry, CharacterSad, etc).
  • [Line text]

Would that be possible?

Please go easy on me as I'm a coding novice!

Comments

  • edited August 13

    It's possible to write custom Actions with new functionality, but the intended way to alter talking animations is to use the expression system.

    Expressions can be defined at the bottom of a character's Inspector, and then set via the [expression:X] token in speech.

    To have this affect the talking animation, however, as opposed to just the character's portrait, you'd need to rely on Sprites Unity Complex for their animation engine - as you can then use an "Expression integer" parameter to control it.

    If you're using Sprites Unity, what you can do is instead rely on a custom token to alter the name of the talk animation being used.

    For example, your speech text could be:

    [talk:Angry]I'm going to be late for work! [talk:Happy]Hang on, it's Sunday!

    More details on this topic can be found in the Manual's "Speech event tokens" chapter, but here's a sample script to handle this:

    using UnityEngine;
    using AC;
    
    public class TalkAnimTokens : MonoBehaviour
    {
    
        private void OnEnable()
        {
            KickStarter.dialog.SpeechEventTokenKeys = new string[1] { "talk" };
            EventManager.OnRequestSpeechTokenReplacement += OnRequestSpeechTokenReplacement;
        }
    
        private void OnDisable ()
        {
            EventManager.OnRequestSpeechTokenReplacement -= OnRequestSpeechTokenReplacement;
        }
    
        private string OnRequestSpeechTokenReplacement(Speech speech, string tokenKey, string tokenValue)
        {
            var character = speech.GetSpeakingCharacter();
            if (character && tokenKey == "talk")
            {
                character.talkAnimSprite = tokenValue;
            }
            return string.Empty;
        }
    
    }
    
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.