ViktorEvil, your solution is correct. The problem you're getting an error is that you are initializing the Trail.scn file inside createTrail(color:geometry:) which is called inside spawnShape() which is called inside renderer(_:updateAtTime:), which causes your console to print the following:
[SceneKit] Error: Scene <SCNScene: 0x2803f5500> is modified within a rendering callback of another scene (<SCNScene: 0x2803e0000>). This is not allowed and may lead to crash
The solution to fix this is to initialize the SCNScene for the trail outside createTrail(color:geometry:).
I got the hint from this StackOverflow answer - https://stackoverflow.com/a/52792424/10654098.
So you need to declare a new variable in GameViewController:
var trailScene: SCNScene!
Then, create a function:
func setupTrailScene() {
		trailScene = SCNScene(named: "Trail.scn")!
}
Then call this function in viewDidLoad(). Then modify your createTrail(color:geometry:) to use the instance variable trailScene instead of declaring the constant inside:
func createTrail(color: UIColor, geometry: SCNGeometry) -> SCNParticleSystem {
		 let node: SCNNode = (trailScene.rootNode.childNode(withName: "Trail", recursively: true)!)!
		 let particleSystem: SCNParticleSystem = (node.particleSystems?.first)!
		 particleSystem.particleColor = color
		 particleSystem.emitterShape = geometry
		 return particleSystem
}
I think this is the best workaround so far, which is to create a particle system node inside a .scn file and get the particle system from that node.
Topic:
Graphics & Games
SubTopic:
SceneKit
Tags: