- Home /
Question by
anitlunia · Jun 08, 2016 at 05:38 PM ·
animationblendersliderskinnedmeshrendererblendshapes
Modify Blend Shapes with a Slider
Hi, so I searched how to make BlendShapes with code using the two methods GetBlendShapewieight and setBlendShapeweight. I tried to attach the slider values to the blend shape value, but somehow it's not showing up. I made my Debug Log of the slider Value and the blendshapeweight value, and they both change to the values 0 to 100. Here is my code (it's very similiar as the documentation): (I'm Using 5.4 beta)
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class BlendShapeManager : MonoBehaviour {
SkinnedMeshRenderer skinnedMeshRenderer;
Mesh skinnedMesh;
void Start () {
skinnedMeshRenderer = GetComponent<SkinnedMeshRenderer> ();
skinnedMesh = GetComponent<SkinnedMeshRenderer> ().sharedMesh;
}
// Update is called once per frame
void Update () {
}
public void ChangeBlendShape(){
GameObject slider1 = GameObject.Find ("HUDCanvas/RightPanel/DetailPanel/Slider_Elf");
if (slider1 != null) {
float horizontalSliderPos = skinnedMeshRenderer.GetBlendShapeWeight (0);
skinnedMeshRenderer.SetBlendShapeWeight (0, slider1.GetComponent<Slider>().value );
skinnedMeshRenderer.updateWhenOffscreen = true;
Debug.Log ("BlendShape value" + skinnedMeshRenderer.GetBlendShapeWeight (0));
Debug.Log ("Slider value" + slider1.GetComponent<Slider>().value);
}
return;
}
}
The Blend shape must show elf ears but nothing happens, any clue?
Here is with a value of 100
And yes, I checked my BlendShapes were imported correctly http://i.imgur.com/cBk9h2R.png
2016-06-08-17-29-18.png
(257.4 kB)
2016-06-08-17-29-03.png
(327.0 kB)
Comment
I'm having the exact same problem. Did you ever find a solution?