I've been updating a SpriteKit/GameplayKit project for Xcode 8 and the new Scene Editor which allows adding Entity-Component information to a scene. I've been to move my entity code into the scene, but I'm having trouble accessing the entity from the corresponding node. As per Apple's documentation:
Any SpriteKit node in the scene to which you’ve attached an entity or components automatically has a GKSKNodeComponent object to manage the relationship between the node and the the GKEntity object it represents.
and
Adding a GKSKNodeComponent object to an entity automatically updates the entity property of the component’s SpriteKit node (an SKNode object) to point to that entity.
The new code I have to load the scene is basically as follows:
guard let newTowerScene = GKScene(fileNamed: "TowerScene"), let rootScene = newTowerScene.rootNode as? SKScene else { return } self.view?.presentScene(rootScene, transition: SKTransition.push(with: .up, duration: 1.75))
Accessing the
GKScene
object returns an array of properly loaded entities, but if I try to access an entity with GKEntity.entity
from a connected node, it returns nil. The node is connected through accessing GKSKNodeComponent.node
from an entity in GKScene
.How do I get
GKSKNodeComponent
and GKScene
to automatically update SKNode
's entity
property as expected?