Hi,
This is probably very easy to fix, or have multiple workarounds but I can’t figure this out for some reasons.
I have this chicken model, with a few animations. In one of them, I want to make it come out of its egg. The egg being part of the chicken mesh, with 2 (yellow) bones. I simply scale those 2 to 0 in all other animations, where the egg should not be visible. It works great in Blender. In Unity, the hatching animation plays but the egg stays invisible (the egg bones scale are animated correctly in the armature in hierarchy). I’m assuming Unity is doing some optimization, “oh look, those vertices don’t seem to do anything, let’s ignore them forever”.
I’ve tried:
to turn off Weld Vertices and Optimize Mesh in the mesh import settings. Also I have considered using blend shapes instead but I don’t think I can animate it directly in blender with the rest of the animation. I can’t really scale the egg to 0.01 or simply move the egg below the ground instead, as I use outline shaders and see through in the game.
It’s probably a core limitation of the import process. (Whoever wrote it in Unity is probably long gone, and whoever owns that feature now is scared to touch it.)
One workaround that comes to mind is to correct the animation in LateUpdate(). Author the animation so that the smallest bone scale you use is 0.05 or so, and then in LateUpdate, just scale bones that are shorter than that threshold to zero. The animation will go right back to the authored size in the next frame.
Thanks! That’s a neat idea. It works nicely and doesn’t add any complexity outside a 2 lines script on some bones.
Here is what I did for anyone wondering: Instead of scaling my bones to 0 in blender, I scaled them to 0.1 (anything small). Then in Unity, I added this script to the bones that I want to hide.
public class ScaleToZeroIfSmall : MonoBehaviour
{
void LateUpdate()
{
if(transform.localScale.sqrMagnitude < 0.05f)
transform.localScale = Vector3.zero;
}
}