Legacy Documentation: Version 5.6 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Mesh.GetNativeIndexBufferPtr

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public function GetNativeIndexBufferPtr(): IntPtr;
public IntPtr GetNativeIndexBufferPtr();

Returns

IntPtr Pointer to the underlying graphics API index buffer.

Description

Retrieves a native (underlying graphics API) pointer to the index buffer.

Use this function to retrieve a pointer/handle corresponding to the Mesh index buffer, as it is represented in the native graphics API. This can be used to enable Mesh manipulation from native code plugins.

Index buffers in Unity are always 16-bit per index. The layout of the index buffer otherwise depends on the Mesh topology that is used (see SetIndices). The most common case of this is Meshes being composed of triangle lists, in which case there are three indices per triangle.

The type of data returned depends on the underlying graphics API:
- IDirect3DIndexBuffer9 on D3D9
- ID3D11Buffer on D3D11
- ID3D12Resource on D3D12
- buffer "name" (as GLuint) on OpenGL/ES
- id<MTLBuffer> on Metal


For most use cases (when writing Mesh data from native code), you need to mark the Mesh as "dynamic" (see MarkDynamic) before getting the native buffer pointer. Generally this switches the buffers to be CPU-writable.

Note that calling this function when using multi-threaded rendering will synchronize with the rendering thread (a slow operation), so best practice is to set up necessary buffer pointers only at initialization time.

See Also: Native code plugins, GetNativeVertexBufferPtr, SetIndices.