- Home /
Connecting two blendshapes
I have two SkinnedMeshRenderer objects (a character and eyelashes) that have matching blendshapes for different facial expressions. Is there a way to set the values for each blendshape on the eyelash object to match whatever value has been set for the identically-named blendshape on the character object?
Answer by rclrobertson · Dec 09, 2018 at 12:41 AM
Solution - I cobbled this together using my limited coding knowledge... this script is attached to the eyelash GameObject and drives its blendshapes with the values of the matching blendshapes on the body GameObject. The order of both objects' blendshapes needs to match so the blendshapes have the same index numbers. Maybe there's a better way but this seems to work just fine for my needs.
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class EyelashBlendshapes : MonoBehaviour
{
int blendShapeCount;
float weight;
SkinnedMeshRenderer skinnedMeshRenderer;
Mesh skinnedMesh;
GameObject source;
SkinnedMeshRenderer sourceMeshRenderer;
void Awake()
{
skinnedMeshRenderer = GetComponent<SkinnedMeshRenderer>();
source = GameObject.Find("Genesis8Female.Shape");
sourceMeshRenderer = source.GetComponent<SkinnedMeshRenderer>();
skinnedMesh = GetComponent<SkinnedMeshRenderer>().sharedMesh;
}
void Start()
{
blendShapeCount = skinnedMesh.blendShapeCount;
}
void Update()
{
for (int i = 0; i < blendShapeCount; ++i)
{
weight = sourceMeshRenderer.GetBlendShapeWeight(i);
skinnedMeshRenderer.SetBlendShapeWeight(i, weight);
}
}
}
Your answer
Follow this Question
Related Questions
Adjust bones transforms to follow blend shapes? 0 Answers
SkinnedMeshRenderer and Colliders 1 Answer
skinnedMeshRenderer class for different game objects 0 Answers
Modify Blend Shapes with a Slider 0 Answers
BlendShape node, name change 0 Answers