Triggering the Play All animtionclip

Hello Everyone I’m trying to trigger the "Play All "animation clip via code and it doesn’t work, other animation clips work when i type out their animation clip name except “Play All”

import * as ecs from '@8thwall/ecs'

ecs.registerComponent({
  name: 'PlayerAnimations',
  data: {
    currentAnimation: ecs.string,
  },

  schema: {
    inputManager: ecs.eid,
  },

  stateMachine: ({world, eid, schemaAttribute, dataAttribute}) => {
    const animations = ['Idle', 'Walk', 'Attack', 'Play All']
    let currentIndex = 0

    const playAnimation = (animationName, playSpeed, canLoop) => {
      const animationComponent = ecs.GltfModel.get(world, eid)
      if (animationComponent) {
        ecs.GltfModel.set(world, eid, {
          animationClip: animationName,
          timeScale: playSpeed,
          loop: canLoop,
        })
        dataAttribute.cursor(eid).currentAnimation = animationName
        console.log(`Swapped to animation: ${animationName}`)
      }
    }

    const handleNext3 = () => {
      currentIndex = (currentIndex + 1) % animations.length
      const nextAnimation = animations[currentIndex]
      playAnimation(nextAnimation, 1, true)
    }

    ecs.defineState('idle').initial()
      .onEnter(() => {
        playAnimation('Idle', 1, true)

        const inputManagerId = schemaAttribute.cursor(eid).inputManager
        if (inputManagerId) {
          world.events.addListener(inputManagerId, 'Scene1', handleNext3)
        }
      })
      .onExit(() => {
        const inputManagerId = schemaAttribute.cursor(eid).inputManager
        if (inputManagerId) {
          world.events.removeListener(inputManagerId, 'Scene1', handleNext3)
        }
      })
  },
})


Use * instead of the animation clip name and it will play them all. :slight_smile:

it works perfectly, thanks ..
Do you know how to play animation clips in parts? For example, I want to play the first 2 seconds of an animation when the ‘Next’ event is triggered, and then play the next 2 seconds the next time the ‘Next’ event is triggered.
Thanks :blush:

I would make a StateMachine that has a state for each animation, and then just make triggers to go to the next animation.

Thanks @GeorgeButler

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.