'Is there someone who used animationDidStop or animationDidStart for SCNAnimation Player?

I am getting animation from a scene file with

func animationFromSceneNamed(path: String) -> SCNAnimationPlayer? {
    let scene  = SCNScene(named: path)
    var animation:SCNAnimationPlayer?
    
    scene?.rootNode.enumerateChildNodes({ child, stop in
        if !child.animationKeys.isEmpty {
            animation = child.animationPlayer(forKey: child.animationKeys[0])
            stop.pointee = false
        }
    })
    return animation
}

And setting it like this

            var animationPlayer = animationFromSceneNamed(path: "hunt.scn")!
            animationPlayer.speed = 0.5
            animationPlayer.animation.duration = 5
            animationPlayer.animation.repeatCount = 1
            animationPlayer.animation.isRemovedOnCompletion = false
            
            
            hunts[0].nodeC.addAnimationPlayer(animationPlayer, forKey: nil)

It plays and ends.

But I need the detect when the animation finished playing there is one variable animationDidStop in Apple's documentation but I could not use this variable to detect end of animation. Could you give an example how to use it?



Solution 1:[1]

I could not find how to use animationDidStop I think it does not work at all instead I found this at where I found code

DispatchQueue.main.asyncAfter(deadline: .now() + 
             (hunts[i].animationPLayer.animation.duration),
                 execute: { [self] in

                  let animationNodeIndex = i

 })

Using this in animation setting, I can detect which animation finished and take needed action.

Solution 2:[2]

you can detect is animation played in Player via Node.animationPlayer(forKey: "key").paused == {true//false}

it returns true or false

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hope
Solution 2 Alek Szcz?snowicz