Search code examples
swiftxcodescenekitvirtual-reality

Where's the particle system file in SceneKit in Xcode 11.3.1


Recently I updated my Xcode to 11.3.1. But while working with SceneKit, I found that I can't create a particle system file.

  • Before

Before

  • After

After

How can I create a particle system in a file now?


Solution

  • SceneKit Library

    In Xcode 14 / 13 / 12 / 11 you have no preconfigured .scnp particle system files anymore. Instead, you can use a Particle System object coming from a Xcode Library (with the same settings in Attributes Inspector as they were in Xcode 10).

    enter image description here

    If you manually placed a Particle System from library into SceneKit's Scene graph you can then retrieve it and setup programmatically. Let's see how it looks like:

    let particlesNode = sceneView.scene?.rootNode.childNode(withName: "particles", 
                                                         recursively: true)
    
    particlesNode?.particleSystems?.first?.isAffectedByGravity = true
    particlesNode?.particleSystems?.first?.acceleration.z = 5.0
    


    Creating particles programmatically

    Or you can easily create a Particle System from scratch using just code:

    let particleSystem = SCNParticleSystem()
        
    particleSystem.birthRate = 1000
    particleSystem.particleSize = 1.45
    particleSystem.particleLifeSpan = 2
    particleSystem.particleColor = .yellow
    
    let particlesNode = SCNNode()
    particlesNode.addParticleSystem(particleSystem)
    
    sceneView.scene!.rootNode.addChildNode(particlesNode)
    

    Creating .scnz file containing Particle System

    • Select a .scn file in Project Navigator (left pane) and choose File – Export...
    • In drop-down menu choose Compressed Scenekit Scene Document .scnz

    enter image description here

    Or you can create .scnp file by renaming .scn – the same way @ycao proposed.