Moving a child object during an animation (2D)

I have a 2D character that’s set up with an idle animation but I need to be able to rotate a child object (his arm). I also need the rotation to stay in place when playing a walking animation too.

The idea is you can rotate the arm (it has a gun at the end) whilst standing still and also whilst walking. I don’t need any transitions as such between the different animations but I need the gun rotation to stay the same.

The problem is that when playing any of the animations the arm cannot be rotated.

The best I can come up with is to set an empty game object on the character where the arm pivot should be then programatically have the arm move to that point.

I was wondering if anyone knows of a better way to do it?

Thanks

I believe what you are looking for is Animation Layers. Animation layers allow you to override the base animation with another animation. They are commonly used to animate a specific body part without animating the entire body. In your case the base layer would have the idle and walking animation and another layer would have the animations for the arm rotating.

Official documentation

Official Training video


An example in 2D from the live training