Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Animator.Rebind() issues

Discussion in '2017.1 Beta' started by Schneider21, Jul 6, 2017.

  1. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    2,915
    I have code from a previous project (5.6.0) where I could successfully add a mesh to a controller with an Animator component using the following code:
    Code (CSharp):
    1.  model.transform.SetParent (controller.transform);
    2. model.transform.localPosition = Vector3.zero;
    3. controller.GetComponent<Animator>().Rebind();
    The code was adapted from @quantumhop's 2015 Answer post here.

    This allowed the skinned mesh renderer of the new mesh to be animated by the Animator of the controller despite not being bound at app initialization.

    In 2017.1.0b10, this no longer works. The new mesh just stays in their T-pose, despite the Animator's settings matching those of an Animator that was initialized with a mesh from the start. I can see the animation state (Grounded) playing in the Animator window when I have the controller selected, but the mesh isn't updating to match.

    Did Animators change somehow and there's now a different way of binding a new mesh at runtime? Or is this a bug?
     
  2. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    2,915
    So after loads of tinkering last night, it seems Rebind() will work if there's no mesh assigned to it to start. I had a mesh that was disabled, and adding another active mesh was not kosher with Rebind. But if the Animator starts out with no child SkinnedMeshRenderer, adding one and calling Rebind will allow it to be animated by the Animator.

    Sort of a long shot throwing this question here, but might as well try: Anyone know of a way to call Rebind() without restarting the playing animation? I've tried some methods I found that involve saving all the Animator's properties first inside a coroutine, then yielding until frame end and then using Play to call the animation at its previous time. The problem with this is that waiting til the end of the frame causes a flash of the character's T-pose that looks worse than starting the animation over.
     
  3. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    316
    @Schneider21 Please file a bug with a small(ish) repro. This is definitely not on purpose.
     
    Schneider21 likes this.
unityunity