Search Unity

Modifiy bone hierarchy of animation clips on import

Discussion in 'Animation' started by martenzander, Feb 18, 2021.

  1. martenzander

    martenzander

    Joined:
    Apr 2, 2020
    Posts:
    1
    Hi,

    I am currently working on an fps game and I am just about to figure out how to set up the arms rig. The arms will always be the same but the weapons can differ. So I have a arms.fbx and many weapons like pistol.fbx, launcher.fbx, sniper.fbx and so on and so on. At runtime I parent each weapon to my right hand bone in my arms prefab. I have an animator component on my arms prefab that controls the animation playback.

    Now since i don't want to have another animator component on each weapon prefab, I rely on merging my animation clips so a simple launcher-reload animation can be controlled by my animator on the arms prefab. To make the merged animation work I need to update the bones hierarchy in my animation clips since the root of my weapon will now be under the right hand of my arms. I tested this approach by changing hierarchy of one of my animation clips in the animation view. It works like a charm! The problem is, as soon as I reimport my animation clips, the hierarchy update is lost and I have to manually recreate the correct bone order in each animation clip. This is tedious and that's why I am looking for a solution to automate this process via script.

    My question is: is there any way to modify the hierarchy of animation clips on import? Or at least at runtime? I am thinking about the AssetProcessor where I modify my clips OnPostprocessAnimation. But I didn't find anything in the docs.

    Looking forward to your input guys, I am stuck!