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.