Undo Button

Hello! I am making a game where you can place blocks and I would like to have an undo button to delete the last placed block! How do I do this?



My code is here:
Please remove .LOG extension from the code


import UIKit

import ARKit

import SceneKit



class ViewController: UIViewController, ARSCNViewDelegate {

    @IBOutlet weak var sceneView: ARSCNView!

    

    override func viewDidLoad() {

        super.viewDidLoad()


        sceneView.delegate = self

        #if DEBUG

        sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints]

        #endif

    }

    

    

    override func viewWillAppear(_ animated: Bool) {

        super.viewWillAppear(animated)


        let configuration = ARWorldTrackingConfiguration()

        configuration.isLightEstimationEnabled = true

        configuration.planeDetection = .horizontal



        if ARConfiguration.isSupported == true {

            sceneView.session.run(configuration)

        } else {

             print("ARKit is not supported on the selected target")

            let alertController = UIAlertController(title: "Not supported", message:

                    "AR is not supported on your device!", preferredStyle: .alert)

                alertController.addAction(UIAlertAction(title: "Dismiss", style: .default))



                self.present(alertController, animated: true, completion: nil)

        }

        

    }

    

    

    

    override func viewWillDisappear(_ animated: Bool) {

        super.viewWillDisappear(animated)

      
        sceneView.session.pause()

    }

    

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

        guard let location = touches.first?.location(in: sceneView) else { return }



        let hitResultsFeaturePoints: [ARHitTestResult] = sceneView.hitTest(location, types: .featurePoint)



        if let hit = hitResultsFeaturePoints.first {

        let finalTransform = hit.worldTransform

        sceneView.hitTest(location, types: .featurePoint)

        let transformHit = hit.worldTransform

        let pointTranslation = transformHit.translation

        let piece = SCNBox(width: 0.07, height: 0.07, length: 0.07, chamferRadius: 0)

        let boxNode = SCNNode()

        boxNode.geometry = piece

        boxNode.position = SCNVector3(pointTranslation.x, pointTranslation.y, pointTranslation.z)

        sceneView.scene.rootNode.addChildNode(boxNode)

        let red = CGFloat(drand48())

        let green = CGFloat(drand48())

        let blue = CGFloat(drand48())

            let color = UIColor(red: red, green: green, blue: blue, alpha: 1.0)

            let material = SCNMaterial()

        boxNode.geometry?.firstMaterial = material

        material.diffuse.contents = color

        myActions.undoNode

        

        

        }

    }



    @IBAction func resetBtnClicked(_ sender: Any) {

        sceneView.scene.rootNode.enumerateChildNodes { (node, stop) in

        node.removeFromParentNode() }

    }

    @IBAction func undoClicked(_ sender: Any) {

        

    }

}



extension float4x4 {

  var translation: simd_float3 {

  let translation = self.columns.3

  return simd_float3(translation.x, translation.y, translation.z)

  }

}






Undo Button
 
 
Q