Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Swapping out SkinnedMeshRenderers and Armatures with One Animator

Discussion in 'Animation' started by ChiliStudio, May 28, 2021.

  1. ChiliStudio

    ChiliStudio

    Joined:
    Jan 19, 2018
    Posts:
    33
    I have an arms SkinnedMeshRenderer + armature, and a gun SkinnedMeshRenderer + armature.

    These both use one animator which is on the parent object.

    Here is what the hierarchy looks like:

    View Model Holder (with animator)
    --- Arms Armature
    --- Arms Mesh
    --- Gun Armature
    --- Gun Mesh

    At runtime, I switch out animator controller overrides, and also I switch out the gun Armature and Mesh.

    Here is my problem though, the animator seems to not want to move the bones on the gun armature when I instantiate the prefabs.

    For example, I instantiate the gun mesh and armature like so:

    View Model Holder (with animator)
    --- Arms Armature
    --- Arms Mesh
    --- New Gun Armature
    --- New Gun Mesh

    The animator does not move the bones of the Gun Armature and thus does not move the mesh, even though I use a different RuntimeAnimatorController override.

    I've also made sure that the Gun Mesh is using the Gun Armature bones, so yes they are linked.

    However, when I spawn in the "View Model Holder" object as a whole (with arms attached to the gun in a prefab), it seems that the animator is linked to the Gun Armature properly, but I need to be able to swap out arms and guns independently.

    I've tried calling Animator.Rebind(), but it doesn't help.

    Can anyone help out? Thanks a lot in advance!
     
  2. ChiliStudio

    ChiliStudio

    Joined:
    Jan 19, 2018
    Posts:
    33
    Solved: One of the bones in the animation was getting "(Clone)" appended to it's name. Fixed with toolArmature.name = toolArmature.name.Replace("(Clone)", string.Empty);