Animation clips with same name but controlling different bones

What I want to achieve is:
I have

  • an exported FBX file containing full bones & mesh & rig information of a character
  • an fbx animation file containing an animation clip animating some bones of the character(say BoneGroupA)
  • another fbx animation file containing an animation clip with the same name animating other bones of the character(say BoneGroupB)

How could I load these files and be able to play the two animation clips together using their shared name so that all the bones of the model could be animated?
e.g.

model.animation.Play(“ClipName”);

Thanks.

To my knowledge, you can’t do this cleanly.

The best solution would be to merge them into a single animation – either into a single FBX in your animation software, or by script in Unity. I think that’s beyond the scope of this question, though. A quick search found this link for copying animation curves in an editor script: How to add new curves or animation events to an imported animation? - Questions & Answers - Unity Discussions

Otherwise they will both need to play at the same time. So instead of just one animation.Play(), you’ll need to set the weights manually and run them simultaneously, or put them on separate layers and play with them PlayMode.StopSameLayer (which is the default).

One problem is that you can’t refer to them uniquely by name, since they have the same name. You can’t use animation[“ClipName”].weight = X, since it’s not clear which “ClipName” you’re referencing. However, you could iterate through the animation component’s AnimationStates and modify each AnimationState whose name matches “ClipName”.

If you can’t merge them into a single animation, it’s probably better to rename one of the imported .anim files to another animation name so you can distinguish between them – for example, rename them to ClipName_BoneGroupA and ClipName_BoneGroupB. Then you can refer to them uniquely. But you still need to play both simultaneously.