Stop Reality Composer

Is there a way to stop a Reality Composer Timeline ? And restart it later on. For me it looks like you can only start a timeline via notification.

and related to it. i have the issue that if the notification to start a certain timeline happens twice or more, it looks as if the timeline actually plays multiple times and animations start to glitch and jump. what is best practise here to avoid this.

Hello @wirmachenbunt , thank you for your question!

Yes, this should be possible, but not through notifications. Notifications let you interact with your scene, but this API is only one-way. For reference, here is a forum answer from my colleague explaining how to use notifications to start a timeline notification.

All timelines you configure inside Reality Composer Pro are actually animations like any other, and can also be accessed via an AnimationLibraryComponent. Note that the entity with the AnimationLibraryComponent with Timeline animations is going to be the root entity in your scene.

Tip: If you're unsure which entity has this component, I recommend using print(myEntity) to print out a debug hierarchy to the console. Alternatively, you can use the "Capture Entity Hierarchy" tool in Xcode when debugging your application.

Then, when you have your entity, you can start the animation like this:

// Get the animation library from the entity.
guard let animationLibraryComponent = myEntity.components[AnimationLibraryComponent.self] else {
    return
}

// Find the specific timeline animation using the scene path to the entity ("/Root") plus the name of the timeline animation (in this example, "/DoMove")
guard let animationResource = animationLibraryComponent.animations["/Root/DoMove"] else {
    return
}

// Retain a reference to the controller that gets returned from the .playAnimation API
self.controller = myEntity.playAnimation(animationResource, transitionDuration: 0, startsPaused: false)

In this example, I have an AnimationPlaybackController named controller that retains a reference to the animation I am interested in. Then I can use .pause() and .resume() on the controller to pause and resume the timeline animation as expected.

This method might also help with the second part of your question. If you retain a reference to the AnimationPlaybackController controlling your animation, you can check if the controller already exists and is playing before calling .playAnimation on your entity again.

Let me know if this helps! Thank you!

Stop Reality Composer
 
 
Q