Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Slice<T>(ulong)

Constructs a typed slice from the BufferID.
Read time 1 minuteLast updated 6 days ago

Definition

public BufferSlice<T> Slice<T>(ulong offset = 0) where T : struct

Parameters

offset

The offset to use for the slice, measured in elements of the specified type.

Returns

Type

Description

BufferSlice<T>A typed slice aliasing the BufferID.

Remarks

Creates a BufferSlice that provides a typed view into the buffer starting at the specified offset. This is a convenience method equivalent to constructing a BufferSlice manually.
The offset is measured in elements of type T, not in bytes. This method provides type safety and helps prevent common offset calculation errors.
Additional Resources: BufferSlice for detailed slice operations and examples.

Examples

// Create a large buffer for mixed dataBufferID sharedBuffer = context.CreateBuffer(1000, sizeof(float));// Create slices using the convenience methodvar firstSection = sharedBuffer.Slice<float>(0); // Elements 0-299var secondSection = sharedBuffer.Slice<Vector3>(300); // Elements 300-399 as Vector3s// Equivalent to manual BufferSlice constructionvar manualSlice = new BufferSlice<float>(sharedBuffer, 0);Debug.Assert(firstSection.Id.Value == manualSlice.Id.Value);Debug.Assert(firstSection.Offset == manualSlice.Offset);