# CopyBuffer(GraphicsBuffer, GraphicsBuffer)

> Copies the contents of one GraphicsBuffer into another.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.7/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

```csharp
public static void CopyBuffer(GraphicsBuffer source, GraphicsBuffer dest)
```

### Parameters

**** (\[GraphicsBuffer]\(/engine/6000.7/script-reference/unityengine/graphicsbuffer)): The source buffer.**** (\[GraphicsBuffer]\(/engine/6000.7/script-reference/unityengine/graphicsbuffer)): The destination buffer.

### Remarks

The GPU copies the buffer contents efficiently.

Total buffer sizes (i.e. [GraphicsBuffer.count](/engine/6000.7/script-reference/unityengine/graphicsbuffer/count.md) multiplied by [GraphicsBuffer.stride](/engine/6000.7/script-reference/unityengine/graphicsbuffer/stride.md)) must match between source and destination buffers. The source buffer must have a [GraphicsBuffer.Target.CopySource](/engine/6000.7/script-reference/unityengine/graphicsbuffer/target/copysource.md) target flag, and the destination buffer must have a [GraphicsBuffer.Target.CopyDestination](/engine/6000.7/script-reference/unityengine/graphicsbuffer/target/copydestination.md) target flag.

```csharp
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    void Start()
    {
        // create a source index buffer and set data for it
        var src = new GraphicsBuffer(
            GraphicsBuffer.Target.Index | GraphicsBuffer.Target.CopySource,
            3, 2);
        src.SetData(new ushort[]{1, 10, 100});
        // create a destination index buffer and copy source into it
        var dst = new GraphicsBuffer(
            GraphicsBuffer.Target.Index | GraphicsBuffer.Target.CopyDestination,
            3, 2);
        Graphics.CopyBuffer(src, dst);

        // check the copied data
        var got = new ushort[3];
        dst.GetData(got);
        Debug.Log($"copied data: {got[0]}, {got[1]}, {got[2]}");

        // release the buffers
        src.Release();
        dst.Release();
    }
}
```

Additional Resources: [GraphicsBuffer](/engine/6000.7/script-reference/unityengine/graphicsbuffer.md), [CommandBuffer.CopyBuffer](/engine/6000.7/script-reference/unityengine/rendering/commandbuffer/copybuffer.md), [Graphics.CopyTexture](/engine/6000.7/script-reference/unityengine/graphics/copytexture.md).
