Hello @lijiaxu,
I'm not able to replicate the issues you are encountering. I'm able to trigger a timeline from a SwiftUI button, and receive notifications fired within a Timeline in my SwiftUI ImmersiveView.
In the sample code project that is associated with WWDC24 session 10102: Compose interactive 3D content in Reality Composer Pro, onReceive(_:perform:)
is used to listen to the notifications fired. For instance, in the MoveToPoppy Timeline, the ReachToPoppy
notification is fired 4 seconds in and the hero robot's HeroRobotRuntimeComponent
is updated.
Additionally, I'm able to add an OnNotification Behavior to the Hero robot to manually trigger a timeline within SwiftUI. I have specified this component to use the Notification Name of MoveToPoppySwiftUINotification
, with an Action of "MoveToPoppy". I'm able to trigger this from SwiftUI using an attachment on the RealityView in ImmersiveView. This allows it to receive the correct scene from the realityKitScene
environment variable:
RealityView { content, attachments in
// Add the initial RealityKit content.
if let immersiveContentEntity = try? await Entity(named: "Immersive", in: realityKitContentBundle) {
content.add(immersiveContentEntity)
}
if let movePoppyButton = attachments.entity(for: "MovePoppyButton") {
movePoppyButton.position = [0, 1.0, -1.0]
content.add(movePoppyButton)
}
} attachments: {
Attachment(id: "MovePoppyButton") {
Button {
NotificationCenter.default.post(
name: NSNotification.Name("RealityKit.NotificationTrigger"),
object: nil,
userInfo: [
"RealityKit.NotificationTrigger.Scene": scene,
"RealityKit.NotificationTrigger.Identifier": "MoveToPoppySwiftUINotification"
]
)
} label: {
Text("Move Poppy")
}.padding(20).glassBackgroundEffect()
}
}
Are you having difficulties replicating this behavior in the sample code?
Could you provide more information as to the issues that you are encountering?
Thanks,
Michael