Search Unity

Blender Armature Animation - Scaling from zero doesn't work

Discussion in 'Asset Importing & Exporting' started by TimHW, Feb 19, 2017.

  1. TimHW

    TimHW

    Joined:
    Sep 8, 2013
    Posts:
    5
    I'm importing a rigged animation where I am scaling meshes that start as if they don't exist (by using a scale of zero) and scale up to full size then back to zero to disappear again.

    The animation looks fine in Blender; however, in Unity the animation only works if everything is above a scale of zero - anything set to a scale of zero in the start pose is never animated (so you never see those meshes at all) and anything that scales to zero mid-way through the animation causes the animation of that mesh to flicker a few times.

    If having a bone pose scaled to zero is not possible, is there a way to achieve a vanish/disappearing effect via Blender animation another way?

    Currently my crude work-around that works (for testing purposes) is having the scale set to a very small number so that it isn't really visible (0.00001); obviously this is not a preferable solution.
     
  2. DimitriX89

    DimitriX89

    Joined:
    Jun 3, 2015
    Posts:
    551
    Do it using scripting. You can easily multilpy scale to zero and back to whatever original value from code. Or even enable/disable the rendering of your object.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. public class EnableDisable : MonoBehaviour {
    4.     //toggles object visiblity by pressing E
    5.     private bool IsVisible = true;
    6.     private Vector3 ScaleOld;
    7.     public float ScaleVisible = 1.0f;
    8.     public float ScaleInvisible = 0.0f;
    9.     public bool DisableRenderer = false;//determines the method we use to hide the object
    10.     private MeshRenderer mesh;//we assume that the object is non-deformable mesh (otherwise use SkinnedMeshRenderer) and is not a sprite (use SpriteRenderer)
    11.  
    12.     void Start () {
    13.         mesh = this.GetComponent<MeshRenderer>();//get the mesh
    14.         ScaleOld = this.transform.localScale;//store the original scale
    15.  
    16.     }
    17.     // Update is called once per frame
    18.     void Update () {
    19.         if (Input.GetKeyDown (KeyCode.E) == true) {// the E key press switches visibility of the object;
    20.             IsVisible = !IsVisible;
    21.         }
    22.         if (DisableRenderer == false) {
    23.             if (IsVisible == true){//set scale method
    24.                 this.transform.localScale = ScaleOld*ScaleVisible;
    25.             } else {
    26.                 this.transform.localScale = ScaleOld*ScaleInvisible;
    27.             }
    28.         } else {//disable renderer method
    29.             mesh.enabled = IsVisible;
    30.         }
    31.     }
    32. }