Forum rules - please read before posting.

Dialogue - Play Speech animation

I modified some of the scripts because I wanted easier head/arm animations as you see in the picture. However when I set the layers in the Player component and then put in an animation, the animations don't play when I set the animation in the dialog action as seen in the picture above.

Does it only work with 2d mecanim or can it work with 3d mecanim animations.

Comments

  • It would come down to the changes that you've made. You're saying that the fields you've added (Body/Arm) aren't playing?

    AC Actions that involve character animation are ultimately handled through their respective AnimEngine classes, i.e. AnimEngine_Mecanim, AnimEngine_SpritesUnity. For "Dialogue: Play speech", the ActionSpeechRun function inside these classes is called.

    I'd first suggest writing such changes in a subclass of ActionSpeech if you're not already - rather than making changes to ActionSpeech directly. That'll make your own changes more clear, as well as allow you to update AC without removing your code.

    2D and 3D characters all rely on Unity's Animator system, so as long as your character has sub-layers defined they should work - AC won't control sub-layers unless commanded to through Actions.

    It might be worth looking into Timeline for layered animation playback, however - particularly if you're working in 3D. A video on AC's Timeline integration can be found here.

  • I updated the scripts in AnimEngine Mecanim, ActionSpeech, Char. I wanted this mainly for character conversations as being able to enter an animation in the layer when a character is talking will be nice.

    Still have no luck getting it to work. What scripts do i need to update exactly if i missed anything?

    I use timeline sparingly because It's difficult getting the character to move somewhere. I had issues with it i posted here before.

  • I can't comment on why things aren't working without knowing what changes you've made.

    But I don't recommend making changes to AC's core scripts. If you use a custom Action that subclasses ActionSpeech as I mention, you can dictate what happens to the character in there.

    Another option is to rely on generated speech ID numbers to assign animations in a separate class that kicks in when the speech is played via the OnStartSpeech custom event. For example:

    using UnityEngine;
    using AC;
    
    public class SpeechAnimationPlayer : MonoBehaviour
    {
    
        [SerializeField] private SpeechAnimation[] speechAnimations = new SpeechAnimation[0];
        [SerializeField] private int bodyLayer = 1;
    
        private void OnEnable () { EventManager.OnStartSpeech += StartSpeech; }
        private void OnDisable () { EventManager.OnStartSpeech -= OnStartSpeech; }
    
    
        private void StartSpeech (AC.Char speakingCharacter, string speechText, int lineID)
        {
            SpeechAnimation speechAnimation = GetSpeechAnimation (lineID);
            if (speechAnimation != null)
            {
                speechAnimation.Play (speakingCharacter.GetAnimator (), bodyLayer);
            }
        }
    
    
        private SpeechAnimation GetSpeechAnimation (int lineID)
        {
            foreach (SpeechAnimation speechAnimation in speechAnimations)
            {
                if (speechAnimation.LineID == lineID)
                {
                    return speechAnimation;
                }
            }
            return null;
        }
    
    
        [System.Serializable]
        private class SpeechAnimation
        {
    
            [SerializeField] private int lineID;
            [SerializeField] private string bodyAnimation;
    
    
            public int LineID { get { return lineID; }}
    
    
            public void Play (Animator animator, int bodyLayer)
            {
                if (!string.IsNullOrEmpty (bodyAnimation))
                {
                    animator.Play (bodyAnimation, bodyLayer);
                }
            }
    
        }
    
    }
    
  • I was able to get it working. I modified the scripts to anim engine, anim engine mecanim, legacy and 2d.

    I'm good now.

    My next tinker is to see if its possible to switch camera in the dialogue speech action. it will make changing cameras when 2 or more characters are talking much easier.

  • My next tinker is to see if its possible to switch camera in the dialogue speech action. it will make changing cameras when 2 or more characters are talking much easier.

    You may be interested in the "Conversation camera" package over on the Downloads page, for an automated solution.

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.