A timeline in RCP will post a notification "Identifier: Completed" when it finishes playing
I am trying to receive this in the following way:
extension Notification.Name {
static let notifyOnAnimationCompleted = Notification.Name("Completed")
}
// in the view
private let AnimationCompleted = NotificationCenter.default.publisher(for: .notifyOnAnimationCompleted)
RealityView {...}
.onReceive(AnimationCompleted)
{ _ in
print("End")
}
This was once working back to July, but it never prints "End" for now
The API changed slightly in Beta 4. The notification name to listen for is now “RealityKit.NotificationTrigger” and the notification identifier you set in RCP on the notification action can be found in the notification output’s user info dictionary under the key “RealityKit.NotificationTrigger.Identifier”. Here is an updated example:
private extension String {
static let notifyOnAnimationCompleted = "Completed"
}
// Note: the Notification.Name was changed to "RealityKit.NotificationTrigger"
private let notificationPublisher = NotificationCenter.default.publisher(for: Notification.Name("RealityKit.NotificationTrigger"))
RealityView { content in
// ...
}
.onReceive(notificationPublisher) { output in
guard let entity = output.userInfo?["RealityKit.NotificationTrigger.SourceEntity"] as? Entity,
let notificationName = output.userInfo?["RealityKit.NotificationTrigger.Identifier"] as? String
else { return }
switch notificationName {
case .notifyOnAnimationCompleted:
// respond to the "completed" notification action
default:
return
}
}