Remove rcp entity onReceive or by function

This is a follow up question for this post

There are several entities I created in rcp that I want to play their animations in a sequence (the order is dynamic)

My plan is to have onReceive detecting the notification, remove the current entity from the scene, add the next entity from the queue...

Somehow, when I call removeFromParent()/removeChild(), either it is not removed or everything is removed and the app crashes, any tips?

Hey @xygu,

It sounds like you are removing the root entity rather than the specific entity in the scene.

For instance using the Composing interactive 3D content with RealityKit and Reality Composer Pro sample code project, I can modify the onReceive callback to remove the robot from the scene:

.onReceive(notificationTrigger) { output in
    guard let entity = output.userInfo?["RealityKit.NotificationTrigger.SourceEntity"] as? Entity,
          let notificationName = output.userInfo?["RealityKit.NotificationTrigger.Identifier"] as? String,
          let heroRobot = scene?.findEntity(named: "hero_robot") else { return }

    print("named: \(entity.name)") // prints "named: Root" 

    heroRobot.removeFromParent()

Let me know if this helps,
Michael

Remove rcp entity onReceive or by function
 
 
Q