# GetAllBoneWeights()

> Gets the bone weights for the Mesh.

## Definition

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

```csharp
public NativeArray<BoneWeight1> GetAllBoneWeights()
```

### Returns

| Type                                                                                           | Description                                                                                                                                                                                                     |
| ---------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [NativeArray\<BoneWeight1>](/engine/6000.6/script-reference/unity/collections/nativearray1.md) | Returns all non-zero bone weights for the Mesh, in vertex index order. The array uses Allocator.None and does not have to be manually disposed. The data remains valid until the mesh is modified or destroyed. |

### Remarks

Use [Mesh.GetBonesPerVertex](/engine/6000.6/script-reference/unityengine/mesh/getbonespervertex.md) to get the number of non-zero weights for each vertex, and then use that to iterate over this data.

For each vertex, the [BoneWeight1](/engine/6000.6/script-reference/unityengine/boneweight1.md) structs are sorted by [BoneWeight1.weight](/engine/6000.6/script-reference/unityengine/boneweight1/weight.md), in descending order.

Additional Resources: [Mesh.SetBoneWeights](/engine/6000.6/script-reference/unityengine/mesh/setboneweights.md), [Mesh.GetBonesPerVertex](/engine/6000.6/script-reference/unityengine/mesh/getbonespervertex.md), [Mesh.boneWeights](/engine/6000.6/script-reference/unityengine/mesh/boneweights.md), [Mesh.GetBoneWeights](/engine/6000.6/script-reference/unityengine/mesh/getboneweights.md) [ModelImporter.maxBonesPerVertex](/engine/6000.6/script-reference/unityeditor/modelimporter/maxbonespervertex.md), [QualitySettings.skinWeights](/engine/6000.6/script-reference/unityengine/qualitysettings/skinweights.md), [SkinnedMeshRenderer.quality](/engine/6000.6/script-reference/unityengine/skinnedmeshrenderer/quality.md).

### Examples

```csharp
using UnityEngine;

public class TestSkinnedMesh : MonoBehaviour {
    void Start()
    {
        // Get a reference to the mesh
        var skinnedMeshRenderer = GetComponent<SkinnedMeshRenderer>();
        var mesh = skinnedMeshRenderer.sharedMesh;

        // Get the number of bone weights per vertex
        var bonesPerVertex = mesh.GetBonesPerVertex();
        if (bonesPerVertex.Length == 0)
        {
             return;
        }

        // Get all the bone weights, in vertex index order
        var boneWeights = mesh.GetAllBoneWeights();

        // Keep track of where we are in the array of BoneWeights, as we iterate over the vertices
        var boneWeightIndex = 0;

        // Iterate over the vertices
        for (var vertIndex = 0; vertIndex < mesh.vertexCount; vertIndex++)
        {
            var totalWeight = 0f;
            var numberOfBonesForThisVertex = bonesPerVertex[vertIndex];
            Debug.Log("This vertex has " + numberOfBonesForThisVertex + " bone influences");

            // For each vertex, iterate over its BoneWeights
            for (var i = 0; i < numberOfBonesForThisVertex; i++)
            {
                var currentBoneWeight = boneWeights[boneWeightIndex];
                totalWeight += currentBoneWeight.weight;
                if (i > 0)
                {
                    Debug.Assert(boneWeights[boneWeightIndex - 1].weight >= currentBoneWeight.weight);
                }
                boneWeightIndex++;
            }
            Debug.Assert(Mathf.Approximately(1f, totalWeight));
        }
    }
}
```
