Hi,
I want to change the color of my particles in SCNParticleSystem from Color A to Color B using CABasicAnimation
I am retrieving color A via
let currentColor: UIColor = (targetColorSphereEmitterNode.particleSystems?[0].particleColor)!
and assign the animation by using
let targetColorAnimation = CABasicAnimation(keyPath: "particleColor")
targetColorAnimation.fromValue = currentColor
targetColorAnimation.toValue = UIColor.magenta
targetColorAnimation.duration = 1.0
targetColorAnimation.isRemovedOnCompletion = true
targetColorSphereEmitterNode.particleSystems?[0].addAnimation(targetColorAnimation, forKey: nil)
Problem is now that the app crashes when executing line 6 with
2017-07-27 18:22:32.039 ColorCube[14484:1136078] -[SCNParticleSystem copyAnimationChannelForKeyPath:animation:]: unrecognized selector sent to instance 0x7fc7916126f0
2017-07-27 18:22:32.042 ColorCube[14484:1136078] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SCNParticleSystem copyAnimationChannelForKeyPath:animation:]: unrecognized selector sent to instance 0x7fc7916126f0'
*** First throw call stack:
(
0 CoreFoundation 0x000000011267db0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010f175141 objc_exception_throw + 48
2 CoreFoundation 0x00000001126ed134 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x0000000112604840 ___forwarding___ + 1024
4 CoreFoundation 0x00000001126043b8 _CF_forwarding_prep_0 + 120
5 SceneKit 0x000000010f9b31d8 SCNAddPropertyAnimation + 133
6 SceneKit 0x000000010f9b3009 SCNAddAnimation + 431
7 SceneKit 0x000000010f97f7d7 __41-[SCNParticleSystem addAnimation:forKey:]_block_invoke + 31
8 SceneKit 0x000000010fa30aa4 C3DTransactionFlush + 2989
9 CoreFoundation 0x0000000112623717 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
10 CoreFoundation 0x0000000112623687 __CFRunLoopDoObservers + 391
11 CoreFoundation 0x0000000112608720 __CFRunLoopRun + 1200
12 CoreFoundation 0x0000000112608016 CFRunLoopRunSpecific + 406
13 GraphicsServices 0x0000000115b35a24 GSEventRunModal + 62
14 UIKit 0x000000010fd8d134 UIApplicationMain + 159
15 ColorCube 0x000000010eb909e7 main + 55
16 libdyld.dylib 0x00000001136a965d start + 1
17 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Not sure what I did wrong here or is this simply the false approach to change the color of the particles?
Max