Class

GKComponentSystem

Manages periodic update messages for all component objects of a specified class.

Declaration

@interface GKComponentSystem<__covariant ComponentType> : NSObject

Overview

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 initWithComponentClass: 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 addComponentWithEntity: 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 updateWithDeltaTime: 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 CVDisplayLinkRef (macOS) timer in a custom rendering engine. The component system then forwards to the updateWithDeltaTime: 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

- initWithComponentClass:

Initializes a component system to manage components of the specified class.

Managing a List of Components

componentClass

The class of components managed by the component system.

components

The component system’s list of components.

- addComponent:

Adds a component instance to the component system.

- addComponentWithEntity:

Adds any instances of the component system’s component class in the specified entity to the component system.

- removeComponent:

Removes the specified component instance from the component system.

- removeComponentWithEntity:

Removes any instances of the component system’s component class in the specified entity from the component system.

Performing Periodic Updates

- updateWithDeltaTime:

Tells all component instances managed by the system to perform their custom periodic actions.

Accessing Components With Subscript Syntax

- objectAtIndexedSubscript:

Returns the component at the specified index in the system’s list of components.

Relationships

Inherits From

See Also

Entities and Components

GKEntity

An object relevant to gameplay, with functionality entirely provided by a collection of component objects.

GKComponent

The abstract superclass for creating objects that add specific gameplay functionality to an entity.