Copy blendshape only if bones exist
I'm using the following script to control blendshapes on objects with different armatures. If an armature doesn't have the bones/mesh required I get the error "Thread Group Size Must Be Above Zero". In this case I just want it to do nothing. Or at least just hide the error (if that's not a terrible idea), because as far as I can tell, apart from the error itself, everything seems to work fine.
[SerializeField] Slider[] sliders;
[SerializeField] SkinnedMeshRenderer[] item;
[SerializeField] SkinnedMeshRenderer model;
public void Awake()
{
for (int i = 0; i < sliders.Length; i++)
{
int index = i;
sliders[i].onValueChanged.AddListener(delegate { SetSlider(index); });
sliders[i].onValueChanged.AddListener(delegate { CopyBlendshapes(index); });
}
}
public void SetSlider(int index)
{
float value = sliders[index].value;
model.SetBlendShapeWeight(index, value);
}
public void CopyBlendshapes(int index)
{
for (int ig = 0; ig < item.Length; ig++)
{
int indexg = ig;
float value = sliders[index].value;
SkinnedMeshRenderer allItems = item[indexg];
allItems.SetBlendShapeWeight(index, value);
}
}
Update: I get no errors in Unity 2019.2b so everything is fine for the moment. I'm still concerned that this could be a problem again if things change when this version is out of beta, so if anyone has an idea for if statements I could try, it would be greatly appreciated.
Your answer
![](https://koobas.hobune.stream/wayback/20220612210148im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
runtime Animator BlendShapes not working 0 Answers
change skinnedmeshrenderer bone, but the blendshape animation invalid 0 Answers
import blendshape from maya 2 Answers
Update bindposes of SkinnedMeshRenderer and re-target animations 0 Answers
Getting the vertex position of a skinnedmeshrenderer after blendshape? 1 Answer