---
title: GKComponent
framework: gameplaykit
role: symbol
role_heading: Class
path: gameplaykit/gkcomponent
---

# GKComponent

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

## Declaration

```swift
class GKComponent
```

## Overview

Overview GKComponent is the abstract superclass for custom component classes you create when building a game with Entity-Component architecture. In this architecture, an entity is an object relevant to the game, and a component is an object that handles specific aspects of an entity’s behavior in a general way. Because a component’s scope of functionality is limited, you can reuse the same component class for many different kinds of entities. You create components by subclassing GKComponent to implement reusable behavior. Then, you build game entities by creating GKEntity objects and using the addComponent(_:) method to attach instances of your custom component classes. At runtime, a component-based game needs to dispatch periodic logic—from an update/render loop method such as update(_:) (SpriteKit) or renderer(_:updateAtTime:) (SceneKit), or a CADisplayLink (iOS) or CVDisplayLink (macOS) timer in a custom rendering engine—to each of its components. GameplayKit provides two mechanisms for dispatching updates: Per-entity. Call each entity’s update(deltaTime:) method, which will then forward to the update(deltaTime:) method of each component. This option can be quickly implemented in games with a small number of entities and components. Per-component. Use a GKComponentSystem object to handle all instances of a specific component class. When you call a component system’s update(deltaTime:) method, it forwards to the update(deltaTime:) method of all the component objects it manages. Because a component system needs no knowledge of your game’s entity/component hierarchy, this option works well for games with complex object graphs. For more information on Entity-Component architecture, read Entities and Components in GameplayKit Programming Guide.

## Topics

### Performing Periodic Updates

- [update(deltaTime:)](gameplaykit/gkcomponent/update(deltatime:).md)

### Working with Entities

- [entity](gameplaykit/gkcomponent/entity.md)
- [didAddToEntity()](gameplaykit/gkcomponent/didaddtoentity().md)
- [willRemoveFromEntity()](gameplaykit/gkcomponent/willremovefromentity().md)

### Initializers

- [init(coder:)](gameplaykit/gkcomponent/init(coder:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Inherited By

- [GKAgent](gameplaykit/gkagent.md)
- [GKSCNNodeComponent](gameplaykit/gkscnnodecomponent.md)
- [GKSKNodeComponent](gameplaykit/gksknodecomponent.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)

## See Also

### Entities and Components

- [GKEntity](gameplaykit/gkentity.md)
- [GKComponentSystem](gameplaykit/gkcomponentsystem.md)
