Forum rules - please read before posting.

expression invocation with timeline markers

Hi. I would like to change expressions directly from timeline with markers. Is there an easy way to implement this or should there be a small script doing it?

Comments

  • edited December 2020

    Personally, I wouldn't recommend the use of Markers for something like this, due to their detachment from bound objects, unlike Tracks.

    It's possible to change expression inside Speech Tracks, by using expression tokens:

    [expression:Name]
    

    (This tutorial covers their use in Actions, but the same technique works in Timeline)

    A character's speech can be made to consist purely of expressions and wait tokens - see the Manual's "Text tokens" chapter for a list of all those available.

    It is possible to set expressions through script, though:

    myCharacter.SetExpression (ID);
    

    Where ID is the ID integer value of the expression.

  • I noticed that in some times the character "speaks" when there's only expression token in Speech track - so that the mouth animation rolls. And I have an idea of code controlled reactions also - an expression and an animation trigger at the same time. Could a Track be used to utilize that?

  • Yes, true - if set to Mecanim, their "Is talking" parameter will be True - but this doesn't necessarily have to cause a talking animation to be played, depending on how the Animator's transitions are wired.

    A custom track type could be written to trigger animations by name, but it'd be more in-keeping with Timeline's workflow to have the animation itself be part of the Timeline via a regular Animation track.

    How are your expressions animated? If they're separate facial animations, have you tried attaching them as animation tracks directly within Timeline, by way of an Avatar Mask to add it to the character's existing animation? That would be more in line with "Unity best practice", and would also allow for control over the intensity / ease in/out of the animation.

  • Expressions use the textures set in dialog expressions - I use the script you gave me in another thread, and shape keys for eye brows and eyes. So the neutral speech texture is swapped for when using an expression.

  • These scripts will provide a bare-bones Timeline track that can be bound to a character, and will change their expressionID in each clip:

    ExpressionBehaviour.cs:

    using UnityEngine;
    using UnityEngine.Playables;
    
    namespace AC
    {
    
        [System.Serializable]
        public class ExpressionBehaviour : PlayableBehaviour
        {
    
            protected int expressionID;
            protected Char character;
    
    
            public void Init (int _expressionID)
            {
                expressionID = _expressionID;
            }
    
    
            public override void ProcessFrame (Playable playable, FrameData info, object playerData)
            {
                if (!Application.isPlaying) return;
                character = playerData as AC.Char;
    
                if (character == null)
                {
                    GameObject characterObject = playerData as GameObject;
                    if (characterObject)
                    {
                        character = characterObject.GetComponent <AC.Char>();
                    }
                }
    
                if (character)
                {
                    character.SetExpression (expressionID);
                }
            }
    
        }
    
    }
    

    ExpressionShot.cs:

    using UnityEngine;
    using UnityEngine.Playables;
    
    namespace AC
    {
    
        public class ExpressionShot : PlayableAsset
        {
    
            [SerializeField] protected int expressionID;
    
            public override Playable CreatePlayable (PlayableGraph graph, GameObject owner)
            {
                var playable = ScriptPlayable <ExpressionBehaviour>.Create (graph);
                var characterAnimation2DBehaviour = playable.GetBehaviour ();
    
                characterAnimation2DBehaviour.Init (expressionID);
    
                return playable;    
            }
    
        }
    
    }
    

    ExpressionTrack.cs:

    using UnityEngine.Timeline;
    
    namespace AC
    {
    
        [TrackClipType (typeof (ExpressionShot))]
        #if UNITY_2018_3_OR_NEWER
        [TrackBindingType (typeof (AC.Char), TrackBindingFlags.None)]
        #else
        [TrackBindingType (typeof (AC.Char))]
        #endif
        [TrackColor (0.2f, 0.6f, 0.9f)]
        public class ExpressionTrack : TrackAsset
        {}
    
    }
    
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.