# ReadBuffer

> Asynchronously copies data from a device buffer to host memory.

## Definition

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

## ReadBuffer\<T>(BufferSlice\<T>, NativeArray\<T>)

Asynchronously copies data from a device buffer to host memory.

```csharp
void ReadBuffer<T>(BufferSlice<T> src, NativeArray<T> dst) where T : struct
```

### Parameters

**** (\[BufferSlice\<T>]\(/engine/6000.6/script-reference/unityengine/lighttransport/bufferslice1)): The [BufferSlice](/engine/6000.6/script-reference/unityengine/lighttransport/bufferslice1.md) specifying the source data on the device.**** (\[NativeArray\<T>]\(/engine/6000.6/script-reference/unity/collections/nativearray1)): The destination array in CPU memory. Must remain valid until the operation completes.

### Remarks

Initiates an asynchronous transfer of data from device memory to host memory. The method returns immediately after enqueuing the operation. Use [IDeviceContext.Flush()](/engine/6000.6/script-reference/unityengine/lighttransport/idevicecontext/flush.md) to ensure the operation begins executing, then use [IDeviceContext.Wait](/engine/6000.6/script-reference/unityengine/lighttransport/idevicecontext/wait.md) or [IDeviceContext.IsCompleted](/engine/6000.6/script-reference/unityengine/lighttransport/idevicecontext/iscompleted.md) with the provided event to determine when the transfer is complete.

The destination [NativeArray\<T>](/engine/6000.6/script-reference/unity/collections/nativearray1.md) must remain allocated and unchanged until the read operation completes, as indicated by the event.

**Warning:** [EventID](/engine/6000.6/script-reference/unityengine/lighttransport/eventid.md) instances are single-use. Do not reuse an event that has been passed to this method.

### Examples

```csharp
// Read data from buffer with event tracking
using var outputData = new NativeArray<int>(1024, Allocator.Persistent);
var readEvent = context.CreateEvent();
context.ReadBuffer(bufferSlice, outputData, readEvent);

// Start execution and wait for completion
context.Flush();
bool success = context.Wait(readEvent);
Assert.IsTrue(success);

context.DestroyEvent(readEvent);
// outputData now contains the buffer contents
```

## ReadBuffer\<T>(BufferSlice\<T>, NativeArray\<T>, EventID)

Asynchronously copies data from a device buffer to host memory.

```csharp
void ReadBuffer<T>(BufferSlice<T> src, NativeArray<T> dst, EventID id) where T : struct
```

### Parameters

**** (\[BufferSlice\<T>]\(/engine/6000.6/script-reference/unityengine/lighttransport/bufferslice1)): The [BufferSlice](/engine/6000.6/script-reference/unityengine/lighttransport/bufferslice1.md) specifying the source data on the device.**** (\[NativeArray\<T>]\(/engine/6000.6/script-reference/unity/collections/nativearray1)): The destination array in CPU memory. Must remain valid until the operation completes.**** (\[EventID]\(/engine/6000.6/script-reference/unityengine/lighttransport/eventid)): Optional event ID to track completion of the read operation.

### Remarks

Initiates an asynchronous transfer of data from device memory to host memory. The method returns immediately after enqueuing the operation. Use [IDeviceContext.Flush()](/engine/6000.6/script-reference/unityengine/lighttransport/idevicecontext/flush.md) to ensure the operation begins executing, then use [IDeviceContext.Wait](/engine/6000.6/script-reference/unityengine/lighttransport/idevicecontext/wait.md) or [IDeviceContext.IsCompleted](/engine/6000.6/script-reference/unityengine/lighttransport/idevicecontext/iscompleted.md) with the provided event to determine when the transfer is complete.

The destination [NativeArray\<T>](/engine/6000.6/script-reference/unity/collections/nativearray1.md) must remain allocated and unchanged until the read operation completes, as indicated by the event.

**Warning:** [EventID](/engine/6000.6/script-reference/unityengine/lighttransport/eventid.md) instances are single-use. Do not reuse an event that has been passed to this method.

### Examples

```csharp
// Read data from buffer with event tracking
using var outputData = new NativeArray<int>(1024, Allocator.Persistent);
var readEvent = context.CreateEvent();
context.ReadBuffer(bufferSlice, outputData, readEvent);

// Start execution and wait for completion
context.Flush();
bool success = context.Wait(readEvent);
Assert.IsTrue(success);

context.DestroyEvent(readEvent);
// outputData now contains the buffer contents
```
