Search code examples
swiftscenekitswift-playground

SceneKit Particle Systems in a Swift Playground


Usually I instantiate SCNParticleSystems by using the file initializer like this:

var stars = SCNParticleSystem(named: "Stars.sncp", inDirectory: nil)

However this project requires a Swift Playground and when I try to use that init function with systems stored in the playground's Resources folder it returns nil (even if I change the specified directory to "Resources" or "/Resources" etc. etc. ).

Are Playground resource paths handled differently to normal apps or am I making a really stupid filenaming mistake?


Solution

  • I think you're doing a mistake in filename extension. It is .scnp and not .sncp.

    Either try without any extension -

    var stars =  SCNParticleSystem(named: "Stars", inDirectory: nil)
    

    or try with correct extension -

    var stars =  SCNParticleSystem(named: "Stars.scnp", inDirectory: nil)