Search Unity

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

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

  1. trasasala


    Aug 26, 2022
    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>().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