title: Multiple serial animations in SceneKit
body: <p>
  I want to be able to run multiple animations, one after another, in SceneKit. I've implemented a function which runs one animation like so:</p>
  
  <pre><code>fileprivate func animateMove(_ move: Move) {
      print("Animate move started " + move.identifier)
  
      // I am creating rotateNode
      let rotateNode = SCNNode()
      rotateNode.eulerAngles.x = CGFloat.pi
      scene.rootNode.addChildNode(rotateNode)
  
      // Then I am selecting nodes which I want to rotate
      nodesToRotate = ...
  
      // Then I am adding the nodes to rotate node
      _ = nodesToRotate.map { rotateNode.addChildNode($0) }
  
      SCNTransaction.begin()
      SCNTransaction.animationDuration = move.animationDuration
  
      SCNTransaction.completionBlock = {
          rotateNode.enumerateChildNodes { node, _ in
              node.transform = node.worldTransform
              node.removeFromParentNode()
              scene.rootNode.addChildNode(node)
          }
          rotateNode.removeFromParentNode()
          print("Animate move finished " + move.identifier)
      }
      SCNTransaction.commit()
  }
  </code></pre>
  
  <p>And then I've tried to run multiple serial animations like so:</p>
  
  <pre><code>    func animateMoves(_ moves: [Move]) {
          for (index, move) in moves.enumerated() {
              perform(#selector(animateMove(_:)), 
              with: move, 
              afterDelay: TimeInterval(Double(index) * move.duration)
          }
      }
  </code></pre>
  
  <p>Everything is animating but the animations don't run in a serial manner. Animations start and finish in unpredictable time. 
  Sample logs from debugger:</p>
  
  <pre><code>Animate move started 1
  Animate move started 2
  Animate move finished 1
  Animate move finished 2
  Animate move started 3
  Animate move finished 3
  </code></pre>
  
  <p>I realise that my approach isn't the best, but only in that way I was able to achieve almost working animations. </p>
  
  <p>I know that there is a SCNAction class available. Maybe I should make many actions within one transaction? If so, could someone explain to me how exactly SCNTransactions work and why the completion SCNTransaction's completion block fires in unpredictable time?</p>