Animating Movement of Object Relative to Parent

Hi guys,

I’ve been battling to make a reload animation for days now. What I’m trying right now is have the hand bone linked to the magazine with a IK constraint so that when I move the magazine during the reload the hand follows the mag. The magazine is parented to the weapon, which is in turn parented to a hand bone. I start with this:

If I try and move the magazine and then save the new location, rotation etc I get this:

How on earth do I animate the position of the magazine relative to the gun?

Thanks in advance for any help you can give. Here is the blend file for anyone who wants to tinker with it:


I think part of the problem comes from having actions on mesh objects objects, actions contain transformation data for one object only then if you apply that to an object it gets inappropriate transforms, you can really only animate and constrain the skeleton in pose mode rather than animating objects directly.

If is not obvious if you have a bone for the magazine, if not you absolutely need one.

It’s a hard file to look at as you uploaded the broken version, would have helped a lot if you uploaded the one before the error occurred and it also looks like you designed it facing the wrong, eg the body is facing up and right instead of straight ahead so its hard to see how its supposed to be.

Edit I noticed your other posts too, you defiantly need a bone for this and then you don’t need to bake constraints for unity

The rotation and scaling error comes from a keyframe on frame 6. While I am not a fan of the scales not being correctly applied (you might run into issues re-importing), it seems to me your real issue is your object hierarchy. I noticed the clip the hand goes to is parented to the right hand bone. There’s some other weird things going on, such as keyframes changing when I switch to different objects and back. I would focus on cleaning up your hierarchy first, and then you will probably want to re-animate things. It is possible to do this animation while keeping items separate if you wanted any item to be picked up off the ground and stuck in the gun, or make clips throwable separate from the gun, but how you implement that depends on the game. Are you using root motion or in-place animations?

FrankieH: Sorry for uploading the broken one but I don’t have any sort of version control so when I messed up my model and accidentally saved it and I couldn’t roll back to the unbroken version. I see why a bone is best for the mag - Blender knows how to save armature keyframes properly. I originally used a magazine bone but I became worried about portability. I wanted to animate one model and then copy and paste my animations into other rigged soldiers and having manually added extra bones seemed like it would mess things up. I realized that my other approaches have their own issues so I’ll retry having the magazine moved by a bone. I don’t see how I can avoid baking animations though - reload animations always need a dynamic constraint that Unity will not support.

Dreaming381: Unfortunately I wiped the file with that error. In any case I don’t see the issue with my hierarchy. Guns are permanently attached to the hand bones, so they are parented for the sake of simplicity, while the magazines have no parent in the hierarchy since they use dynamic parenting via constraints. I’m using in place animations, since I was lazy. What I normally do is do a animation where the soldier runs or whatever between two positions and once that is done I change the animation so that the soldier is on one spot throughout the animation.

Thanks for your help guys.

baking occurs automatically when you export so you shouldn’t have to do it manually.

Re version control, I always run dropbox on my work folders and it backs up every file every time I save it, it’s been really handy. Although it does popup dialogues in unity when loading assets sometimes saying file is in use click to try again.

I also noticed you used the magazine object as the ik target, just in case its not clear the ik target needs to be a bone that is part of the rig.

Version Control: You can also press “F2” and click the “+” beside save to increment the file name.

FrankeH: I stand corrected. Child Of Constraints do not get baked, but the IK constraints do. I should get into the habit of version control, it’s going to be quite crucial for making a game.

thedaemon: I’d personally rather have a sort of git-like version control as opposed to copying the entire file, but git doesn’t work on my pc. I use my own file naming convention. The blender one has it’s advantages though in that you can’t make a typo when naming your new version which would lead to confusion later.

Child of constraints do get baked but it has to be used on a bone not an object, as said before you can’t mix bone and object animation in any controllable way

FrankieH: I see. I read that constraints do not import into Unity at all. I didn’t know that armature constraints were baked.

Yep. All armature animation constraints get baked. It is actually a weird limitation that you can’t mix object and armature animations in Blender. It has something to do with the limitations of the stack system I think. Regardless, you actually can use IK constraints dynamically in Unity using avatars. The constraints aren’t the same as Blender, but they are pretty powerful and easy to set up. They allow you to do things dynamically, so for example, you have an animation where the character bends down to pick up an item, you can interpolate your IK hand target to the object over several frames, and your character can pick up the object no matter where it is on the ground.

Given your typical animation style, why aren’t you using root motion? It allows the animation to move the character (as you stated you typically initially animate it) and then you can control speed and direction using blend trees in Unity.

And just for everyone’s reference, when it comes to animations, Unity only reads the animation curves of objects and bones. This is why baking constraints work, but constraints themselves don’t. It also means that if you take into account curves in the graph editor when animating, you can make your animations framerate independent.

Sorry to hijack the thread but can you go into more detail about the IK in unity? and is it only on humanoid rig?

Right now, yea. It uses the Avatar/retargeting system that Unity advertises. It is a completely independent system from Blender though. It’s purpose is more for placing feet correctly on the ground and if you wanted to dynamically have the hands go somewhere. It’s good for ragdoll stuff too if that’s your thing. In my opinion though, it is a pain to animate for since it uses its own embedded twist bone system that doesn’t have a 1:1 with Blender. But then again, I struggle with Rigify due to how unconstrained the joints are, so if you are more comfortable than I am, then you’ll get a lot of mileage out of it.

Oh yea! Unity’s documentation has a step-by-step guide on how to set up a Blender Rigify character to Unity’s Mecanim avatar.