A container for associating GameplayKit objects with a SpriteKit scene.
SDKs
- iOS 10.0+
- macOS 10.12+
- Mac Catalyst 13.0+
- tvOS 10.0+
Framework
- Gameplay
Kit
Declaration
class GKScene : NSObject
Overview
When you create a scene in the Xcode SpriteKit scene editor, Xcode automatically creates a GKScene
object to manage any GameplayKit objects you add to the scene (entities, components, or pathfinding graphs) and archive them alongside the SpriteKit scene content.
To use a SpriteKit scene that contains GameplayKit objects, load the scene file with the GKScene
init(file
method. You can then use the entities
and graphs
properties to access the GKEntity
(and associated GKComponent
) objects and GKGraph
objects in the scene, and the root
property to access the scene’s SpriteKit content.
Note
Any SpriteKit node in the scene to which you’ve attached an entity or components automatically has a GKSKNode
object to manage the relationship between the node and the the GKEntity
object it represents.
For more information on Entity-Component architecture and pathfinding graphs, see Entities and Components and Pathfinding in GameplayKit Programming Guide.