Blending walk and run animations in RealityKit

Hi everybody,

I have 2 separate animations run.usdz and walk.usdz animation files which are loaded perfectly in Reality Composer Pro and in the RealityKit application. I want to gradually increase the speed of my player by switching blending weight values from 0.0 (walking) to 1.0 (full speed running).




let rabbit = await RabbitBuilder.loadWalkingRabbit()
let runningRabbit = await RabbitBuilder.loadRunningRabbit() 
                
rabbit.scale = SIMD3(0.05, 0.05, 0.05)
runningRabbit.scale = SIMD3(0.05, 0.05, 0.05)
                
let walkAnimation = rabbit.availableAnimations
let runAnimation = runningRabbit.availableAnimations

RabbitWalker.walkAnim = walkAnimation.first!
RabbitWalker.runAnim  = runAnimation.first!


        guard let walk = RabbitWalker.walkAnim,
              let run  = RabbitWalker.runAnim else { return }

        let blendTree = BlendTreeAnimation<JointTransforms>(
            BlendTreeBlendNode(sources: [
                BlendTreeSourceNode(source: walk.definition, name: "walk", weight: .value(1 - weight)),
                BlendTreeSourceNode(source: run.definition,  name: "run",  weight: .value(weight))
            ]),
            name: "rabbitLocomotion",
            repeatMode: .repeat,
            offset: TimeInterval(elapsed) 
        )

// I have runtime error after executing this line: "Cannot add incompatible timeline type to blend tree."
        guard let resource = try? AnimationResource.generate(with: blendTree) else { return }
        entity.playAnimation(resource)


static func loadWalkingRabbit() async -> Entity? {
        do {
            let scene = try await Entity(named: "Scene", in: realityKitEnvironmentBundle)
            guard let rabbit = await scene.findEntity(named: "RabbitWalk") else {
                return nil
            }
            await rabbit.removeFromParent()
            return rabbit

        } catch {
            return nil
        }
    }
    
    static func loadRunningRabbit() async -> Entity? {
        do {
            let scene = try await Entity(named: "Scene", in: realityKitEnvironmentBundle)
            guard let rabbit = await scene.findEntity(named: "RabbitRun") else {
                return nil
            }
            await rabbit.removeFromParent()
          return rabbit

        } catch {
            return nil
        }
    }


But when I run this code I have this error;

Cannot add incompatible timeline type to blend tree.

By the way I have looked to developer's sample codes from here but I couldn't find any relevant BlendTreeAnimation sample which blends 2 animations.

I would very happy if someone could direct me to a solution.

Regards.

Hey @WishGrantingFactory,

This error occurs because your walk and run animations are loaded from two separate entities. Even if both USDZ files use the same skeleton, each Entity load creates its own animation timeline — and BlendTreeAnimation requires all sources to share the same timeline.

Can you author your content so that both animations exist on a single entity? Attach both animation clips to one entity in Reality Composer Pro so they both appear in rabbit.availableAnimations. Then you can build the blend tree from that shared source.

Let me know if this helps.

Thanks,
Michael

Hi Michael,

Thank you for quick reply. Yes both animation share the same skeleton.

Here are the steps that I followed;

  1. I have added T-Pose style rabbit entity to my scene
  2. I created an Animation Library and added RabbitWalk and RabbitRun animations respectively.
  3. I loaded those animations like entity.availableAnimations[0] & entity.availableAnimations[1] but I have the same error.
  4. I then created a new Timeline for the Rabbit entity
  5. Create a separate 'Walk' animation and make it recursive.
  6. Create a separate 'Run' animation and make it recursive as well.
  7. Then I loaded those last 2 animation to my blend animation function but I have the same problem again.

Here is the RCP project.

Am I missing something?

Regards.

Hey @WishGrantingFactory,

I would have expected that to work, I'll have to work with the team to gain a better understanding of what is happening here. I'd greatly appreciate it if you could open a bug report, include a sample project that replicates the issue, and post the FB number here once you do.

Bug Reporting: How and Why? has tips on creating your bug report.

As a possible workaround could you animations on the same timeline? You can then create a clip of the animation with the part of the animation that you want to loop as described in Create a clip of an animation.

Thanks,
Michael

Blending walk and run animations in RealityKit
 
 
Q