OpacityComponent does not work on device

I've been trying to animate the OpacityComponent to fade in/out entities in my scene. I've tried animating the component with an AnimationResource as well as tried animating with a custom System. Both worked fine in the simulator, but failed on device.

AnimationResource: When I animated the opacity of an entity using an animation with an opacity bind target, the entity would not change opacity until I physically looked away from the object. It's almost as if the device keeps an entity visible for as long as you keep looking at it, but once you look away it plays the animation.

System: I created a custom system that manually changes the opacity over time, however, on device the gradual fade of the entity doesn't work. Instead, the entity literally pops in/out of view instead of fading.

Can someone explain exactly how this component is supposed to be used? The simulator plays the animations exactly the way I would expect, but on device it's completely different.

Edit: I'm trying to change the opacity of entities with a VideoMaterial added to a ModelComponent. The fade animations are performed at certain points in the video that are triggered by an AVPlayer time boundary observer.

Replies

I haven't seen the issues you're seeing, but here is how we use it in our app and it works fine (sometimes it struggles to play smoothly on heavy assets).

// Add the opacity component, otherwise the animation doesn't do anything.
//
someEntity.components.set(OpacityComponent(opacity: 1.0))

// Create an animation to fade the opacity to zero.
//
let animationDefinition = FromToByAnimation(from: Float(1.0), to: Float(0.0), duration: 1.0, bindTarget: .opacity)
if let animationResource = try? AnimationResource.generate(with: animationDefinition) {
    // Play the animation.
    //
    someEntity.playAnimation(animationResource)
}

Not sure what's going wrong on your side, but hopefully this code snippet helps.

  • I'm playing the animation in the same exact way and it works perfectly in the simulator, but on device it doesn't play immediately. Once I turn my head away from the object I can see it fade out/in. I'm not sure if this is a bug related to using the OpacityComponent on an entity with a VideoMaterial.

Add a Comment