<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "GameplayKit",
  "identifier" : "/documentation/GameplayKit/GKEntity/addComponent(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "GameplayKit"
    ],
    "preciseIdentifier" : "c:objc(cs)GKEntity(im)addComponent:"
  },
  "title" : "addComponent(_:)"
}
-->

# addComponent(_:)

Adds a component to the entity.

```
func addComponent(_ component: GKComponent)
```

## Parameters

`component`

An instance of a [`GKComponent`](/documentation/GameplayKit/GKComponent) subclass.

## Discussion

You create components by subclassing [`GKEntity`](/documentation/GameplayKit/GKEntity) to implement reusable behavior. Then, use this method to incorporate the behavior of a component class into that entity.

An entity’s [`components`](/documentation/GameplayKit/GKEntity/components) list never has more than one instance of any component class—if the entity already contains a component of the same class as the `component` parameter, calling this method will replace that component.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)