Search Unity

I get a error message from skinnedMeshRenderer.SetBlendShapeWeight()

Discussion in 'Animation' started by SmallSage, Feb 26, 2019.

  1. SmallSage

    SmallSage

    Joined:
    Sep 4, 2017
    Posts:
    5
    Thank you anyone!
    This error message:
    "Array index (0) is out of bounds (size=0)
    UnityEngine.SkinnedMeshRenderer:SetBlendShapeWeight(Int32, Single)"

    This follow is my code:
    Code (CSharp):
    1.  
    2. if (index >= 0 && index < skinnedMeshRenderer.sharedMesh.blendShapeCount && !skinnedMeshRenderer.sharedMesh.Equals(null))
    3. {
    4.     skinnedMeshRenderer.SetBlendShapeWeight(index, Mathf.Clamp(value * 100f, 0, 100));
    5. }
    6.  
    Steps&PS:

    1.This mesh from "Mesh.CombineMeshes(combineInstances,false,false)" of multiple mesh.
    2.This mesh's BlendShapes from "Mesh.AddBlendShapeFrame(,,,,)"
    3.This error happen in Load scene from a to b.

    best wishes!
     
    Last edited: Feb 26, 2019
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    That sounds like a bug.

    Can you GetBlendShapeWeight or try logging other details of the blend shapes on the mesh?
     
  3. SmallSage

    SmallSage

    Joined:
    Sep 4, 2017
    Posts:
    5
    Good idea,Thank you very much :D , I will try it and i added more details for this question.
    Maybe you will have other idea.
     
  4. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    You're probably changing the blend shapes without the renderer knowing they have been changed so its weight array is the wrong size.

    Try skinnedMeshRenderer.sharedMesh = skinnedMeshRenderer.sharedMesh to let it know the mesh has changed. If that doesn't work, set it to null then back to the mesh.
     
  5. SmallSage

    SmallSage

    Joined:
    Sep 4, 2017
    Posts:
    5
    Yes, you are right,I made a mistake, I did
    "skinnedMeshRenderer.sharedMesh=null;skinnedMeshRenderer.sharedMesh=mesh;"
    before i did
    "mesh.AddBlendShapeFrame(,,,,)"

    I fixed it just now

    That's kind of you :D