GKComponentSystem
Manages periodic update messages for all component objects of a specified class.
Declaration
class GKComponentSystem<ComponentType> where ComponentType : GKComponentOverview
A GKComponentSystem object manages periodic update messages for components in a game that uses Entity-Component architecture. Use a component system to perform per-frame logic for all components of a specific class without traversing your game’s object hierarchy to dispatch update messages.
Each GKComponentSystem object manages components of a specific GKComponent subclass. You create a component system with the init(componentClass:) initializer, specifying the component class it will work with. Then, you register the components used by the entities in your game with the addComponent(_:) or addComponent(foundIn:) methods. The component system will then forward any component-specific messages it receives to all registered instances of its component class.
The most important of the component-specific messages is the update(deltaTime:) method. Call this method from your game’s update/render loop—that is, from a method such as update(_:) (SpriteKit) or renderer(_:updateAtTime:) (SceneKit), or from a CADisplayLink (iOS) or CVDisplayLink (macOS) timer in a custom rendering engine. The component system then forwards to the update(deltaTime:) method of all the GKComponent subclass instances it manages, allowing those objects to perform per-frame update logic.
For more information on Entity-Component architecture, read Entities and Components in GameplayKit Programming Guide.
Topics
Creating a Component System
Managing a List of Components
componentClasscomponentsaddComponent(_:)addComponent(foundIn:)removeComponent(_:)removeComponent(foundIn:)