Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Animator rebind only works when triggered through the Unity editor ?

Discussion in 'Animation' started by trasasala, Jan 25, 2023.

  1. trasasala

    trasasala

    Joined:
    Aug 26, 2022
    Posts:
    1
    Hi there,

    I can't seem to programmatically rebind my animator when I instantiate a new character mesh during runtime.

    In my game, players can choose their character mesh from a pre-defined selection of prefabs. To make this work, I have a script which destroys the previous and instantiates the selected prefab with the skinned mesh rendered component (FYI this object is a child of the player object which contains the animator component - the player object remains the same, only the child object with the skinned mesh is replaced).

    Once this swap is executed, my player is stuck in the T-pose and there are no animations until I rebind the animator. BUT this only works if I disable/enable the animator component through the editor UI. If I try to rebind the animator in the script with
    myPlayerObject.GetComponent<Animator>().Rebind()
    or
    myPlayerObject.GetComponent<Animator>().enabled = false / true
    it continues to be suck in the T-pose.

    I wonder why this is? Any experience or suggestions on how to fix this?

    FYI: Bone root reference and naming is correct, the correct avatar is also assigned to the skinned mesh rendered mesh.
     
    Last edited: Jan 25, 2023