Shape Key Drivers and Mecanim

I’ve seen that it’s possible to use shape keys created in Blender with Unity (https://www.youtube.com/watch?annotation_id=annotation_3900583123&feature=iv&src_vid=ah8j4e1mw4Y&v=6vvNV1VeXhk), but I don’t want to have to adjust the shape key manually with a script etc. Like in Blender, I would like the rotation of the bone associated with the shape key in question to determine the shape key value.

Is it possible to import the shape key drivers into Unity? If so, how do you do it and would it work with mecanim?

Sorry, I think this was better posted in Unity Answers: http://answers.unity3d.com/questions/1288012/shape-key-drivers-and-mecanim.html

I think if you take a look at the animation curves window, you can directly make a curve that affects the shape key values. You can’t currently directly get the shape key values from Blender, so this and/or scripting is the only way I know to do what you want.

That’s what I gathered so far, but I’m looking for a script that can make the rotation of a bone responsible for the value of the shape key. I know it must be pretty straightforward to do, I think I just need a bit of step by step guidance to get there (i.e., how do you reference the bone, where do you attach the script, how do you ensure that the angles are correct etc.)

Well, I can get you started if you intend on scripting instead. The bone is going to work just like an actual transformed child gameObject of the parent bone(or object if it is the root bone). To access the bone on your script, I would simply put a public variable for a transform on the script, and drag&drop the bone/transform onto that public variable. Then in the script, you can access the transform(likely the local one), and you can scrub through animation to see exactly what the rotation values are going between, and then in your script, interpolate between those two values to get how far the shape key should happen. Then you will want to adjust the exact values, for example if they should start changing from the beginning or of it should have a “deadzone” and change only at 25% of the rotation, and the same thing for the end. And you can change the “curve” as well, so instead of directly being a linear change, it could change faster later for example.

1 Like

Thanks for that :slight_smile: I’ll post the script here when it’s done as it might benefit others who read this.