Using Blend Shapes in 4.3

I was very excited to see that blend shapes are now supported in 4.3, however, I can’t seem to get it to work. I created a simple cube with two blend shape deformers on it in Maya and imported it as a .mb asset. After playing around for a few hours, I still haven’t found out how to use my control curves to drive the blend shape deformers…am I missing something? What is the correct process for setting it up in/for Unity.

Thanks!

1 Like

I did a quick test, and imported a model we had created in MAX using morphs. I found a field to edit the value of the morph on the Skinned Mesh Renderer component on the objects that had them. Seems to be working correctly for me.

Under Skinned Mesh Renderer one of the first fields was “BlendShapes” which when expanded would show any imported from the model.

Edit: The model was exported from MAX in an FBX format. Not sure if that would make any difference on the Unity end for importing.

Thanks, I was able to replicate your results using the skinned mesh renderer setting, however that looks like it’s only to test the blend shapes. I can’t get it to work when creating animations within the animation editor.

I’m beginning to wonder whether it would be a better workflow to do all facial animation along with character animation in maya and just import the animations into unity for in game cinematics now that it supports blend shapes.

Yup ditto here. I know I seem to complain about this every single time, but we need some form of documentation on these new features.

Anyway I’ve done my own searches and tests and I can’t seem to extract the Morpher animation from 3DSMax to Unity.

Same setup as you fellas, with a cube and three morph targets, and a 100 frame animation test.

I’ve tried every FBX option I could think of (i.e. Bake, Curve Filters) and nothing is exported.

In Unity however yes I see my Blendshapes in the SkinMeshRenderersweet…and I can scrub the values and get the morphing to indeed work.

  • Quick Note: you only need to export the primary object, not the morph targets themselves. Makes for a nice clean import.

In the interim, you can create a new animation clip in the Animation editor, and set keys to create your own motion, but beyond that I don’t know. I’ll keep trying.

-Steven

(My fear is that they only considered supporting Maya ‘Blendshape’ animation curves)

I’m using Maya and am still having the se problem as you using Max.

Oh fair enough, you did say Maya…hmmmm.

Some help Unity Dev’s?

-Steve

Other than steveb’s suggestion to duplicate/create a new animation and set the values that way, you can use driver bones. Basically, create a bone for each shape key, named the same, parented to a root bone. Move the driver bones along an axis, and then attach script that will set the blend shape values depending on the driver bone positions relative to the root bone.

As a bonus, you can also set up a very similar driver in your editor of choice (you can in blender, I’m pretty sure you can in max and maya), to allow you to animate with just a rig, instead of having to mess with wherever your blend shape animation controls are hidden.

Have a script
(Note: there are other ways to find the drivers/computing offset, including just assuming that the driver bones are starting at their zero position, and store those positions on awake to compute offsets later)

using UnityEngine;

public class BlendShapeDriver : MonoBehaviour
{
    private const string DefaultRootBoneName = "BlendShapes";
	[SerializeField]
	SkinnedMeshRenderer _renderer;
    //parent bone to all the child bones.
	[SerializeField]
	Transform _rootControlBone;
    //scaling to apply to the bone's offset
	[SerializeField]
	Vector3 _scale = new Vector3(0, 100, 0);

	Transform[] _controlBones;

	void Awake()
	{
        //first, make sure everything is set up to prevent errors
		if (!_renderer)
		{
		    _renderer = GetComponentInChildren<SkinnedMeshRenderer>();
            if (!_renderer)
            {
                Debug.LogError("A SkinnedMeshRenderer is required to operate", this);
                enabled = false;
                return;
            }
		}
        if (!_rootControlBone)
        {
            //look for a bone. Not ideal.
            _rootControlBone = RecurseSearch(transform, DefaultRootBoneName);
            //still couldn't find one? just use the root, as the object might be optimized with the driver bones exposed
            if (!_rootControlBone) _rootControlBone = transform;
        }

	
		_controlBones = new Transform[_renderer.sharedMesh.blendShapeCount];
		foreach(Transform child in _rootControlBone)
		{
			var ind = _renderer.sharedMesh.GetBlendShapeIndex(child.name);
            //I'm guessing here. GetBlendShapeIndex has no documentation. Based on FindIndex's operation
			if (ind == -1) continue;

			//found a matching blend shape to this bone. Use it.
			_controlBones[ind] = child;
		}
	}

    Transform RecurseSearch(Transform parent, string searchName)
    {
        if (parent.name == searchName) return parent;
		if (parent.childCount == 0) return null;

		Transform didFind;
        foreach (Transform trans in parent)
        {
			didFind = RecurseSearch(trans, searchName);
			if (didFind) return didFind;
        }
		return null;
    }

	void Update()
	{
		for(int i = 0; i < _controlBones.Length; i++)
		{
			if (!_controlBones[i])continue;

            //dot will multiply by scale, and then sum the axis.
			_renderer.SetBlendShapeWeight(i, Vector3.Dot(_controlBones[i].localPosition, _scale));
		}
	}
}

in action:

1 Like

First off very creative idea cerebrate, wonderful! This is useful regardless as you can have bone orientation driven morphing to simulate musculature and such. Awesome!!

Now if I may…

.…I figured this out!

I double checked the process and it most definitely works. The operative element was Mecanim, as I was curious why this was mentioned in the Features yet not mentioned anywhere else (hence why documentation would be ideal, but maybe that’s just me…)

How to Achieve Blendshape Animation in Unity from Animation Suite of Choice(Directions are for 3DSMax):

  • Create your object or character, create morph targets and animate away. I’m going to assume here you know how to do this, if not, tons of tutorials around. Optional - Add a Skin modifier AFTER the Morpher and rig/skin as you would for a character. The order in the modifier stack is crucial(from bottom to top)…Edit****Mesh/PolyMorpherSkin
  • FBX Export as you as you always have been, just make certain that under Deformations, you have ‘Morphs’ checked. No need to check anything else at all (i.e. no need for Bake)
  • Import of course, and in the Project Panel, take a look at your newly imported asset in the Inspector. Other than the obvious checkbox ‘Import BlendShapes’ the only other thing I checked is ‘Loop Time’ in the Animations tab, but you should already know this if you have experience importing animated characters. Also note you have an animation, probably named Take 001…this is where you morph animation is believe it or not!
  • Here is the important part…The Animator Controller! This step is different depending on if you exported a BlendShape object with or without Skin, and therefore bone animation. If you imported a skinned character, there should automatically be an Animator Controller with the same name as your asset. If you animated a BlendShape asset without any skin, you will need to Create/Animator Controller, and name it something logical.
  • You have your Animator Controller; drag your newly imported asset into your scene, and with it selected, make certain you have you Animator Controller in the Controller slot of the Animator Component. BlendShape-only assets will state ‘None (Runtime Animator Controller’ ) in this slot if you don’t add a controller, and effectively nothing will happen.
  • Open the Animator tab, and add a State and add the animation from the imported asset…Take 001 if you haven’t already renamed it.
  • Now with your asset selected in the Hierarchy panel, if you go back to the Animation tab (not Animator tab! :smile: )…tada!!..you should see the name of the animation (Take 001 (Read-Only)) and the list of controllers including your morphs!!! Scrub it on the timeline or hit Play and see it in action!!

I think I wrote that correctly, but if not feel free to yell at me!

Huge relief guys and now I can actually sleep sound knowing this actually does work.

Cheers!!

-Steven

See also:

Thanks a lot, we were struggling with this also.

+1 on the need of documentation/tutorials/whatever to help us use new features when they come out.

Can Anyone let me know the procedure for MAYA. Please stuck for 2days.I am not able to get the blend shapes animation to unity. in unity I am getting the blend shapes but not the Animation clip (take001).Help.

Thanks Graham, that’ll be helpful too.

The issue in this thread is that there is absolutely no documentation for this feature other than how to export/import the fbx, let alone what I outline above. I can’t fathom how features can be announced and applauded but then not a single word of instruction is offered.

Sure in hindsight it appears simple enough; you could argue if you forged ahead as you normally would importing animations and setting up Mecanim one would stumble across this solution, but is that how this should work??

This is happening far too frequently with Unity. The documentation needs a complete once-over, adding missing things, adding tutorials for the more esoteric features/functions and a general ‘refresh’ for the current state of the program.

Cheers guys

-Steven

If you’re not seeing an animation clip, then you’re not exporting it from Maya. Double-check your settings in the FBX panel.

Otherwise the only unique instructions above for Max is the modifier stack. If you know how to skin/rig/blendshape in Maya then the rest of my directions apply to Unity.

Cheers

Hi SteveB,

Thanks for the reply.I have double checked it.With out exporting the same from maya how I would get the FBX?

Here I am attaching the FBX screenshot have a look

Hmmm that looks correct.

Just to go step by step (and because I have to think about this), can you at least export skeletal animation? I want to know if ANY anim clips are exported before figuring out if its the BlendShapes causing the problem.

If you’re only trying to export blendshapes and not skeletal motion, then yea I’m going to have to do some research.

Cheers

-Steven

Oh yah. i am getting all other animations which are applied to the skeletal mesh . The only problem is with the blend shapes.Not able to get the BS ( blend shapes) animation.If I am exporting only with the BS animation, then I am not able to see the clip in unity.

May I just ask - I got “read only” sign on Animation timeline, over morphs. Even morph (bland shape) animation work, we could be able to adjust curves and keyframes, couldn’t we? Is there something I don’t see?

So just to be clear:

  • Export BS WITH Skeleton - You get an animation clip (e.g. Take 001), but no Morph anim
  • Export BS WITHOUT Skeleton - No animation clip, so no anything

I have to ask the stupid questions now, as next time you test all this, I encourage you to be thorough and test a variety of scenarios so we can expedite fixing your problem:

  • Did you follow my instructions and set up your Animator Controller, your Mecanim State and include the clip to play?
  • Is it set to Loop in case you missed it the first playthrough?
  • In Maya, are you simply storing BlendShapes or are you also animating them in the timeline?
  • Do you see animation curves for the BlendShapes in the Graph Editor?
  • Did you try setting keys on the object itself, not just BlendShape keys? It’s possible Maya FBX export is not grabbing the BlendShape keys on export because it thinks the object itself isn’t being animated?

Again I know these are seemingly silly questions, but I have to ask to help narrow it down. I’m going to try to do an export from Maya myself right now and see what I get.

-Steven

Good question. I found no way to edit the curves myself either (Read-Only).