RealityKit animation with bindTarget: .opacity doesn't work

I want to fade objects in and out, and while setting an entity's OpacityComponent works, animating it doesn't seem to do anything.

In the following code the second sphere should fade out, but it keeps its initial opacity. On the other hand, the animation that changes its transform works. What am I doing wrong?

class ViewController: NSViewController {

    override func loadView() {
        let arView = ARView(frame: NSScreen.main!.frame)
        let anchor = AnchorEntity(.world(transform: matrix_identity_float4x4))
        arView.scene.addAnchor(anchor)
        let sphere = ModelEntity(mesh: .generateSphere(radius: 0.5))
        anchor.addChild(sphere)
        sphere.components.set(OpacityComponent(opacity: 0.1))
        let sphere2 = ModelEntity(mesh: .generateSphere(radius: 0.5))
        sphere2.position = .init(x: 0.2, y: 0, z: 0)
        anchor.addChild(sphere2)
        sphere2.components.set(OpacityComponent(opacity: 0.1))
        sphere.playAnimation(try! AnimationResource.makeActionAnimation(for: FromToByAction(to: 0, timing: .linear), duration: 1, bindTarget: .opacity))
        sphere.playAnimation(try! AnimationResource.makeActionAnimation(for: FromToByAction(to: Transform(translation: SIMD3(x: 0.1, y: 0, z: 0)), timing: .linear), duration: 1, bindTarget: .transform))
        view = arView
    }
    
}

I created FB22098456.

@Nickkk thank you for your question! And thank you for your feedback ticket!

The first thing I recommend is to do your test with a material, as you might see unexpected results with a nil (pink stripe) material.

Second, try animating opacity with this line of code (replace line 14 in your code above with this line):

sphere.playAnimation(try! AnimationResource.generate(with: FromToByAnimation<Float>(to: 0, duration: 1, bindTarget: .opacity)))

Let me know if that helps!

Thanks. Using AnimationResource.generate(with:) rather than AnimationResource.makeActionAnimation(for:duration:bindTarget:) solves the issue (and setting a material makes sure that the sphere actually fades out and doesn't just disappear at the end). I don't understand the difference though, the two lines of code seem almost identical to me.

RealityKit animation with bindTarget: .opacity doesn't work
 
 
Q