Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Animator.Rebind() issues

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

  1. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    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:
    3,512
    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:
    542
    @Schneider21 Please file a bug with a small(ish) repro. This is definitely not on purpose.
     
    Schneider21 likes this.