OMGPOP desires to attract extra consideration to this query.
I’ve the next code:
closing class PassthroughEmitterNode: SKEmitterNode {
static func load(fnWithoutExtension: String, in bundle: Bundle) -> SKEmitterNode? {
guard
let sksPath = bundle.path(forResource: fnWithoutExtension, ofType: “sks”),
let sksData = strive? Information(contentsOf: URL(fileURLWithPath: sksPath)),
let unarchiver = strive? NSKeyedUnarchiver(forReadingFrom: sksData),
let texturePath = bundle.path(forResource: fnWithoutExtension, ofType: “png”),
let textureImage = UIImage(contentsOfFile: texturePath)
else { return nil }
// Required to decode into subclass
unarchiver.setClass(self.classForKeyedUnarchiver(), forClassName: “SKEmitterNode”)
let emitter = unarchiver.decodeObject(forKey: NSKeyedArchiveRootObjectKey) as? PassthroughEmitterNode
unarchiver.finishDecoding()
guard let emitter else { return nil }
// We nonetheless must set texture, as a result of the feel file just isn’t in fundamental bundle
emitter.particleTexture = SKTexture(picture: textureImage)
// Should allow person interplay to obtain contact
emitter.isUserInteractionEnabled = true
return emitter
}
}
That is similar to studying a SKScene subclass occasion from SKS file (equivalent to this: utilizing sks file with SKScene subclass).
Nevertheless, this does not work. The unarchiver’s decoding at all times returns nil.
However unarchiving to SKEmitterNode class itself works. The subclass does not work.