Error: Array index (0) is out of bounds (size=0)

I set it to find the blend Shape Count but it is set to 0 then printed so then the error shows.

    private void Start()
    {
        rend = GetComponent<SkinnedMeshRenderer>();
        cubeSpring = GetComponent<SkinnedMeshRenderer>().sharedMesh;
        blendShapeCount = cubeSpring.blendShapeCount;
        print("count " + blendShapeCount);
      
    }

     private void Update()
    {
      
        rend.SetBlendShapeWeight(0, weight);
        realWeight = Mathf.Lerp(realWeight, weight, 30f * Time.deltaTime);
    }

  
    public void activateSpring()
    {
        weight = 100f;
        StartCoroutine(wait(0.25f));
    }

  
    private IEnumerator wait(float sec)
    {
        yield return new WaitForSeconds(sec);
        this.weight = 0f;
        goingUp = false;
        yield break;
    }

Please give the exact line where the error occurs, and spell out what your actual question is.

Index 0 is outside the bounds of a 0-length array, if that’s what you’re confused about. (Arrays are numbered from 0 to n-1; for example, an array of size 10 has elements numbered {0, 1, 2, …, 8, 9}. “10” would be out-of-bounds of a 10-size array. Similarly, “0” is out-of-bounds of a 0-size array.)

this is the line.
rend.SetBlendShapeWeight(0, weight);

Is there a way to change the out of bounds number?

Make sure your cubeSpring has at least one blend shape.

(you are trying to change the weight of whichever blend shape is first in the list, but there is no “first” because the list is completely empty)

Can you make blend shapes in blander?

I don’t actually know what a “blend shape” is. I just know that you’re trying to modify one that you don’t have.

Presumably there was some reason that you wrote the above code in the first place that tries to modify a blend shape. If you trace that reasoning backwards, you should eventually run into some bit of logic that rested on the belief that you would have one to modify. Either that was an unreasonable belief, in which case you need to change it and restart your chain of reasoning from that point, or it was a reasonable belief, in which case it should reference a reason why you were going to have a blend shape, and you should chase that down to figure out why you don’t have one now.

1 Like

Oh I got it. In blender I made key shapes and unity was able to uses them.