# Copy

> Copies a buffer of UCS-2 text. The copy is encoded as UTF-8.

## Definition

* **Type:** Method
* **Namespace:** [Unity.Collections](/engine/6000.7/script-reference/unity/collections.md)
* **Assembly:** UnityEngine.ManagedKernelModule

## Copy(byte\*, int, int, char\*, int)

Copies a buffer of UCS-2 text. The copy is encoded as UTF-8.

```csharp
public static CopyError Copy(byte* dest, out int destLength, int destUTF8MaxLengthInBytes, char* src, int srcLength)
```

### Parameters

**** (\[byte\*]\(https\://learn.microsoft.com/dotnet/api/system.byte)): The destination buffer for writing UTF-8.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Outputs the number of bytes written to the destination.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The max number of bytes that will be written to the destination buffer.**** (\[char\*]\(https\://learn.microsoft.com/dotnet/api/system.char)): The source buffer for reading UCS-2.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of chars to read from the source.

### Returns

| Type                                                                        | Description                                                                                                                                                                                                                              |
| --------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [CopyError](/engine/6000.7/script-reference/unity/collections/copyerror.md) | [CopyError.None](/engine/6000.7/script-reference/unity/collections/copyerror/none.md) if the copy fully completes. Otherwise, returns [CopyError.Truncation](/engine/6000.7/script-reference/unity/collections/copyerror/truncation.md). |

### Remarks

Assumes the source data is valid UCS-2.

## Copy(byte\*, ushort, ushort, char\*, int)

Copies a buffer of UCS-2 text. The copy is encoded as UTF-8.

```csharp
public static CopyError Copy(byte* dest, out ushort destLength, ushort destUTF8MaxLengthInBytes, char* src, int srcLength)
```

### Parameters

**** (\[byte\*]\(https\://learn.microsoft.com/dotnet/api/system.byte)): The destination buffer for writing UTF-8.**** (\[ushort]\(https\://learn.microsoft.com/dotnet/api/system.uint16)): Outputs the number of bytes written to the destination.**** (\[ushort]\(https\://learn.microsoft.com/dotnet/api/system.uint16)): The max number of bytes that will be written to the destination buffer.**** (\[char\*]\(https\://learn.microsoft.com/dotnet/api/system.char)): The source buffer for reading UCS-2.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of chars to read from the source.

### Returns

| Type                                                                        | Description                                                                                                                                                                                                                              |
| --------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [CopyError](/engine/6000.7/script-reference/unity/collections/copyerror.md) | [CopyError.None](/engine/6000.7/script-reference/unity/collections/copyerror/none.md) if the copy fully completes. Otherwise, returns [CopyError.Truncation](/engine/6000.7/script-reference/unity/collections/copyerror/truncation.md). |

### Remarks

Assumes the source data is valid UCS-2.

## Copy(byte\*, int, int, byte\*, int)

Copies a buffer of UCS-8 text.

```csharp
public static CopyError Copy(byte* dest, out int destLength, int destUTF8MaxLengthInBytes, byte* src, int srcLength)
```

### Parameters

**** (\[byte\*]\(https\://learn.microsoft.com/dotnet/api/system.byte)): The destination buffer.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Outputs the number of bytes written to the destination.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The max number of bytes that will be written to the destination buffer.**** (\[byte\*]\(https\://learn.microsoft.com/dotnet/api/system.byte)): The source buffer.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of chars to read from the source.

### Returns

| Type                                                                        | Description                                                                                                                                                                                                                              |
| --------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [CopyError](/engine/6000.7/script-reference/unity/collections/copyerror.md) | [CopyError.None](/engine/6000.7/script-reference/unity/collections/copyerror/none.md) if the copy fully completes. Otherwise, returns [CopyError.Truncation](/engine/6000.7/script-reference/unity/collections/copyerror/truncation.md). |

### Remarks

Assumes the source data is valid UTF-8.

## Copy(byte\*, ushort, ushort, byte\*, ushort)

Copies a buffer of UCS-8 text.

```csharp
public static CopyError Copy(byte* dest, out ushort destLength, ushort destUTF8MaxLengthInBytes, byte* src, ushort srcLength)
```

### Parameters

**** (\[byte\*]\(https\://learn.microsoft.com/dotnet/api/system.byte)): The destination buffer.**** (\[ushort]\(https\://learn.microsoft.com/dotnet/api/system.uint16)): Outputs the number of bytes written to the destination.**** (\[ushort]\(https\://learn.microsoft.com/dotnet/api/system.uint16)): The max number of bytes that will be written to the destination buffer.**** (\[byte\*]\(https\://learn.microsoft.com/dotnet/api/system.byte)): The source buffer.**** (\[ushort]\(https\://learn.microsoft.com/dotnet/api/system.uint16)): The number of chars to read from the source.

### Returns

| Type                                                                        | Description                                                                                                                                                                                                                              |
| --------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [CopyError](/engine/6000.7/script-reference/unity/collections/copyerror.md) | [CopyError.None](/engine/6000.7/script-reference/unity/collections/copyerror/none.md) if the copy fully completes. Otherwise, returns [CopyError.Truncation](/engine/6000.7/script-reference/unity/collections/copyerror/truncation.md). |

### Remarks

Assumes the source data is valid UTF-8.

## Copy(char\*, int, int, byte\*, int)

Copies a buffer of UTF-8 text. The copy is encoded as UCS-2.

```csharp
public static CopyError Copy(char* dest, out int destLength, int destUCS2MaxLengthInChars, byte* src, int srcLength)
```

### Parameters

**** (\[char\*]\(https\://learn.microsoft.com/dotnet/api/system.char)): The destination buffer for writing UCS-2.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Outputs the number of chars written to the destination.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The max number of chars that will be written to the destination buffer.**** (\[byte\*]\(https\://learn.microsoft.com/dotnet/api/system.byte)): The source buffer for reading UTF-8.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of bytes to read from the source.

### Returns

| Type                                                                        | Description                                                                                                                                                                                                                              |
| --------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [CopyError](/engine/6000.7/script-reference/unity/collections/copyerror.md) | [CopyError.None](/engine/6000.7/script-reference/unity/collections/copyerror/none.md) if the copy fully completes. Otherwise, returns [CopyError.Truncation](/engine/6000.7/script-reference/unity/collections/copyerror/truncation.md). |

### Remarks

Assumes the source data is valid UTF-8.

## Copy(char\*, ushort, ushort, byte\*, ushort)

Copies a buffer of UTF-8 text. The copy is encoded as UCS-2.

```csharp
public static CopyError Copy(char* dest, out ushort destLength, ushort destUCS2MaxLengthInChars, byte* src, ushort srcLength)
```

### Parameters

**** (\[char\*]\(https\://learn.microsoft.com/dotnet/api/system.char)): The destination buffer for writing UCS-2.**** (\[ushort]\(https\://learn.microsoft.com/dotnet/api/system.uint16)): Outputs the number of chars written to the destination.**** (\[ushort]\(https\://learn.microsoft.com/dotnet/api/system.uint16)): The max number of chars that will be written to the destination buffer.**** (\[byte\*]\(https\://learn.microsoft.com/dotnet/api/system.byte)): The source buffer for reading UTF-8.**** (\[ushort]\(https\://learn.microsoft.com/dotnet/api/system.uint16)): The number of bytes to read from the source.

### Returns

| Type                                                                        | Description                                                                                                                                                                                                                              |
| --------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [CopyError](/engine/6000.7/script-reference/unity/collections/copyerror.md) | [CopyError.None](/engine/6000.7/script-reference/unity/collections/copyerror/none.md) if the copy fully completes. Otherwise, returns [CopyError.Truncation](/engine/6000.7/script-reference/unity/collections/copyerror/truncation.md). |

### Remarks

Assumes the source data is valid UTF-8.
