animation.PlayQueued - Why does it play instantly?

Hi There,

I am trying to write a simple function that allows the current animation (which would be looping) to play up to it’s last frame, then play a list of other animations, the last one being a looping one again.

A sequence that would resemble this:-

  • LoopingAnimation
  • TransitionalAnimation
  • TransitionalAnimation
  • TransitionalAnimation
  • LoopingAnimation

I originally did this:-

    public void QueueUpAnimations(params string[] anims)
    {
        //Queue up animations
        animation.wrapMode = WrapMode.Once;
        animation[anims[anims.Length - 1]].wrapMode = WrapMode.Loop;
        foreach (string anim in anims)
        {
            animation.PlayQueued(anim, QueueMode.CompleteOthers);
        }
    }

But the final animation never looped.

So i then had to more forcably set the wrapmode by setting up animation events to tell me when each animation starts and used this:-

    string m_sCurrentAnimation   = "NOT SET";
    bool   m_bSetWrapModeOnStart = false;
    string m_sAnimationOnStart   = "NONE";

    public void QueueUpAnimations(params string[] anims)
    {
        //Queue up animations
        animation.wrapMode = WrapMode.Once;
        foreach (string anim in anims)
        {
            animation.PlayQueued(anim, QueueMode.CompleteOthers);
        }

        //Setup for final animation's wrap mode
        m_bSetWrapModeOnStart = true;
        m_sAnimationOnStart = anims[anims.Length - 1];
    }

    void OnAnimationStart(string animationname)
    {
        m_sCurrentAnimation = animationname;

        if (m_bSetWrapModeOnStart  (m_sCurrentAnimation == m_sAnimationOnStart))
        {
            animation.wrapMode = WrapMode.Loop;
            m_bSetWrapModeOnStart = false;
        }
    }

And now it works fine the first time after I start the scene, the default Idle animation runs up to its last frame, then the transitional animations are played, then the final animation loops around. nice. But every time after that I do it, the current animation does not continue and the first transitional one starts immediately.

I feel like im trying to jump through hoops to achieve this very simple task of animation queuing… Is there a correct way that I should be doing this? I must be understanding the system incorrectly.

Many thanks in advance

Aahh so I think i noticed something more specific… If the current looping animation has completed once already, then PlayQueued will start it immediately. Is there any way to get around this?

Nevermind… found a ‘nicer’ bodge :(. Only really works if only this script sets the animation so that the variable m_asLastAnimSet can be tracked.

    AnimationState m_asLastAnimSet = null;
    public void QueueUpAnimations(params string[] anims)
    {
        //Current animation now set to not loop
        m_asLastAnimSet.wrapMode = WrapMode.Once;

        //Horrible bodge to ensure looping animation continues to its 'last frame'
        if (m_asLastAnimSet.time > m_asLastAnimSet.length)
        {
            //Get the current time
            float t = m_asLastAnimSet.time;
            //Wrap it into animation length
            while (t > m_asLastAnimSet.length)
            {
                t -= m_asLastAnimSet.length;
            }
            //Set animation time
            m_asLastAnimSet.time = t;
        }

        //Queue up animations
        foreach (string anim in anims)
        {
            m_asLastAnimSet = animation.PlayQueued(anim, QueueMode.CompleteOthers);
            m_asLastAnimSet.wrapMode = WrapMode.Once;
        }
        m_asLastAnimSet.wrapMode = WrapMode.Loop;
    }

Should this be a bug report??