1

I have an Action Sequence that has a duration of 0.5 and then gets hidden when it hits 0 secs:

enter image description here

How can know when the action is done so that I can remove it from the scene? There isn't a way to do it with a SCNNode, I'm hoping an AnchorEntity is different.

func session(_ session: ARSession, didAdd anchors: [ARAnchor]) {
    for anchor in anchors {
        if let anchorName = anchor.name, anchorName == "LaserBeam" {
            
            placeObject(named: anchorName, for: anchor)
        }
    }
}

func placeObject(named entityName: String, for anchor: ARAnchor) {
    do {
        
        let laserEntity = try ModelEntity.load(named: entityName)
        let anchorEntity = AnchorEntity(anchor: anchor)
        anchorEntity.addChild(laserEntity)

        arView.scene.addAnchor(anchorEntity)
        
    } catch let err as NSError {
        print(err.localizedDescription)
    }
}
Lance Samaria
  • 17,576
  • 18
  • 108
  • 256

1 Answers1

1

You use either the subscribe(to:in:_:) or publisher(for:on: ) ) if you prefer Combine on your Scene and pass AnimationEvents.PlaybackCompleted as event to subscribe to.

Additionally, when using the publisher function you can use any Combine operator like filter(_:) to subscribe to just the specific animation you want.

jlsiewert
  • 3,494
  • 18
  • 41