Reputation: 289
I am weighing my options to add custom data to SCNNode
instances.
One way I have been thinking of is using associated objects.
The other is to use an SCNNode
subclass.
Concerning associated objects, I am wondering about the possibility to archive the scene with NSKeyedArchiver.archiveRootObject(_:toFile:)
and retain data.
Concerning an SCNNode
subclass, that would mean my scene graph would be made of that subclass instances as opposed to SCNNode
instances. I was wondering if that could cause trouble.
I have made a request to Apple in the bug reports to add a userData
property to SCNNode
similar to that of SKNode
in SpriteKit
, but in the meantime, I need to find a way with what we got.
Upvotes: 3
Views: 849
Reputation: 13462
Just like CALayer
, SCNNode
is a key-value coding compliant container class and allows you to use KVC for arbitrary keys. SCNNode
conforms to the NSSecureCoding
protocol and will automatically archive these additional keys.
Upvotes: 5
Reputation: 7646
A downside to subclassing is that you won't be able to use the Xcode Scene Editor with your scene graph. That might not matter to you.
If you're not using it for anything else, the name
property might help you. You could store a unique key there, and use it to index the custom data.
Upvotes: 0