Send messages to the scene

I saw onnoffitacation in the Behavior configuration of Reality Composer pro, which asked me to enter the Nofficatition name, that is to say, this requires swift in Xcode to send a message. There is a message name in the message, so I hope you can write an list for me how to use Swift in Xcode to send a message containing the message name.

Answered by Vision Pro Engineer in 791192022

Use the following snippet to post the notification.

NotificationCenter.default.post(
  name: NSNotification.Name("RealityKit.NotificationTrigger"),
  object: nil,
  userInfo: [
    "RealityKit.NotificationTrigger.Scene": scene,
    "RealityKit.NotificationTrigger.Identifier": "Name_You_Provided_On_Trigger_In_RCP"
  ]
)

In the above snippet, scene refers to the RealityKit scene.

@Environment(\.realityKitScene) var scene

Note: The interaction system won't be ready to receive Notifications right away, so wait at least half a second after loading your content before posting the notification.

Accepted Answer

Use the following snippet to post the notification.

NotificationCenter.default.post(
  name: NSNotification.Name("RealityKit.NotificationTrigger"),
  object: nil,
  userInfo: [
    "RealityKit.NotificationTrigger.Scene": scene,
    "RealityKit.NotificationTrigger.Identifier": "Name_You_Provided_On_Trigger_In_RCP"
  ]
)

In the above snippet, scene refers to the RealityKit scene.

@Environment(\.realityKitScene) var scene

Note: The interaction system won't be ready to receive Notifications right away, so wait at least half a second after loading your content before posting the notification.

Send messages to the scene
 
 
Q