- Home /
Why is my Mechanim Animator overriding my BlendShapes?
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.
Thanks in advance for the help!
Need to bump this as it is very far from view at this point.
Is there some more information I could provide to help get this question answered?
i need to know what happened with this. have you gotten it working/ What exactly works?
You can see my answer below, it is what worked for me.
Answer by kburkhart84 · Nov 09, 2014 at 02:03 AM
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.
I notice you say, "Via Code". Does the BlendShape value in the skinned mesh renderer work if you set the value in editor?
It does work as well via the editor. But the true power of blendshapes is best realized when you can modify things in code, making animations and the like. Just being able to modify it in the editor isn't near as useful, though I guess it would work for creating variations of the mesh that don't change at game time.
Thanks for the reply. I just wanted your confirmation; this doesn't work for me. Trying to work out why that is. Have you tried the same method with other models?
I haven't tried with anything except for some quick tests of my own quicky models, as I haven't actually needed the functionality in a project yet. If you want, you can send me the blend, and I can try to mess with it. I'm exclusively using Unity 5(Pro) now that it has come into "Release Candidate" status, but I don't think anything will have changed as far as this stuff goes.
I never found more information honestly. Once I found a solution I left it alone.
Answer by Nanako · May 25, 2015 at 04:03 PM
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
Answer by medhue · May 23, 2015 at 08:21 PM
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.
O$$anonymous$$, so you are basically masking away the mesh, leaving the rig, right? So because the mesh is still a child of the rig/bones, it will still deform, but not in an overriding fashion? Am I understanding it right?
Yes, I think you have it right. I've just been informed tho that we have problems again, but I have not personally looked at the problem yet. So, we likely will have more to say.
Problem solved. It's the blender export method.
Binary breaks it. it works fine with ascii fbx export.
Answer by deab · Jun 18, 2018 at 08:32 AM
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.
Answer by Wothanar · Jan 30, 2019 at 02:40 AM
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