# ComponentExtensions

This class allows you to copy Unity components from certain gameobjects, so you can add these copied components onto other gameobjects if needed.

### Available methods

```csharp
public static T GetCopyOf<T>(this T comp, T other) where T : Component
```

*This extension method creates copy of given component.*

*Example:*

```csharp
var rb = firstGO.GetComponent<Rigidbody>();
secondGO.AddComponent<Rigidbody>().GetCopyOf(rb) as Rigidbody;
```

***

```csharp
public static T AddComponent<T>(this GameObject go, T toAdd) where T : Component
```

*This extension method copies component **toAdd** and adds it onto given gameobject.*

*Example:*

```csharp
var rb = firstGO.GetComponent<Rigidbody>();
secondGO.AddComponent(rb);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://heroicsolo.gitbook.io/heroic-engine/basics/engine-utilities/componentextensions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
