I’m working with Blender. I have a very simple cylinder that has a bending animation using 3 bones. It also contains a single blend shape. I know I can’t animate the blendshape in Blender and expect that animation to come across, but I know I CAN directly set the values in code and/or on the object inspector. I can confirm that I can get the modified blend shapes, or I can get the bending thing to happen, but I can’t get both.
So, I have some very simple code here in C#.
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour
{
private SkinnedMeshRenderer renderer;
public float test = 0;
void Awake()
{
renderer = GetComponent<SkinnedMeshRenderer>();
test = 0;
}
void Update()
{
Debug.Log(renderer.GetBlendShapeWeight(0));
renderer.SetBlendShapeWeight(0, test);
}
}
I get no errors. And if I don’t have the animator on the root object, I can modify at runtime via the inspector the float “test”. It then applies via the update function to the blendshape value and it works perfect.
But…If I have the animator attached to the root object(which I would need in order to have bone based animations going on), the blend shape no longer works. The blend shape gets stuck at whatever value it was left at in Blender. I have the debug log going. When I put the debug call right after I set the Blend Weight, it shows correctly like I want want it. But if I show the value right before I set it, it shows as the “stuck” value. This leads me to believe that Unity(the animator) is forcing the blend weight to whatever it was in Blender3d.
So, how can I fix this? It was my understanding that I would be able to combine both blend weight changes with bone based animation, but it doesn’t appear to be so.
I can’t believe this. Once again, I find a solution to my own problem, though it makes no sense. I’m not completely sure as to why this works, and hopefully someone better with Blender can explain it.
My understanding of the “relative” setting was so that the keys would be relative to the basis right…then at least in Blender, you could easily change the keys and it would apply them at any values, allowing you to drive them via animations, or drivers based on positions of bones or whatever. Normally this is fine in Blender, and I didn’t expect most of this stuff to work in Unity due to a complete lack of the whole animation/driver system. But I expected the shape keys to work like normal.
Somehow, by making the keys not be set as “relative” it works. I’m not sure what this setting does exactly though it appears to be forcing animation frames or something like that. But, whatever it is doing wrong for Blender it is doing right for Unity. I currently in my crap test cylinder have a simple looping bend animation. Via code, I can now set the shape keys however I want to, in any “mix&match” combination and it just works. It no longer forces the blend shape value to whatever it was when exporting from Blender. Weird…but hey, if it works I’ll take it.
Now, if anyone would please comment on how/why this works, it would be great, so I can learn the reason why it works. Thanks in advance.
to make blendshapes work properly at runtime, export your fbx from blender using the ascii exporter. We were unable to get it working with binary. Ascii works out of the box with no other special configuration
You can use the binary exported, but selecting ‘relative’ means the shapekeys are added to the animations with constant 0 value. Switch off ‘relative’ and you can freely change the values by script.
what happend if the model come from daz and it was working and some way the mecanim just start overriding again the blendshapes i cant change them on editor cant change it via script in late update the jesus crist blendshape stay on 0 HOW AND WHY THIS! PEOPLE I WILL DIE FROM A BRAIN CANCER COZ THIS! LOL
Hey, it’s been quite a while since 2014 but here’s what worked for me:
If I got it correct, the shape key values are also affected by the animation of your mesh. So seperating animations and shape keys fixes the problem.
Separate your main rigged mesh (T-Posed character for me) and its animations as different .fbx files,
Then in Blender make the shape key changes for your main mesh.
Assamble your .fbx’s in Unity Animator.
Now you should have full control.
Leaving a possible solution here in case anybody comes across this issue. In my case, I imported a character from Daz and could not access the blendshapes during animation. This is because the animation contained character mesh data, which overrides the blendshapes. In order to remove the mesh data from the animation, expand the character mesh in the asset window, locate the animation, and duplicate it. Double click the new animation and in the left side panel you will see the keyframes for the bones. Look for character mesh data here (you may need to scroll down) and remove all of it, so only the keyframes remain. Now you should be able to use your blendshapes during animation.
We were able to get the blend shapes working again. How we did it, is we created Avatar Masks, that masked out the mesh in all the animations and the Animator Controller. So, I had to go thru all the animations and create masks on each of them, with the top mesh, not the rig, unchecked. Then, we created an Avatar Mask in the project folder, chose the right Avatar in the mask, and using transform, cause our character has a custom rig, and unchecking the mesh, leaving the whole rig.