Aim offset and animation out of sync(?) - how do I fix?

I finally figured out my AI anims for both non-combat and combat mode, and I combined usage of anim montage for torso and aim offset.
However, I am now in a pickle - anims are out of whack(sync?) when I plug in aim offset: https://www.youtube.com/watch?v=2kPf2JGWCSU

What am I doing wrong and how can I fix this (UE 4.26.2) ? Thanks

Worth noting that pistol and character are animated together, but exported as separate FBX files. In UE4 I use Set Master Pose BP node to combine character and gun skeletal meshes. Both character and the gun use the same Animation Blueprint. Everything looks in sync until I add aim offset into the equation.

You are doing a few conceptual things wrong:

First.
The gun shouldn’t be animated to move up and down. It’s movement should come from the IK bone that it is attached to.
Fixing that will at least keep the gun in place.

Second.
Order of operations. Normally you put an AO before verything else because it adjusts the bones of whatever follows.
(This may not change anything in this specific case, but its worth noting nonetheless).

Third.
If you have a gun that uses the same skeleton as the character, you definitely need a master pose component to keep the 2 syncing. Waste of processing, but point 1 already covered that.

In animation software the gun is space-switched to the hand from holster and back, when needed). It’s part of the character. I simply exported character and gun separately, because I can just change visibility on the gun when I need to hide it (when NPC dies or whatever).
The whole point of this setup is not to attach anything because attached components “eat” away from performance, especially on mobile. Or so I’ve been told. So having weapon animated with the character seems like a good idea to avoid attaching anything.
I could keep it as character’s mesh, but then there is no way to hide the gun that is part of the whole character mesh (and no, masking it not the way to go when it comes to performance).

I already have master pose (setup is per UE4’s docs about modular characters). What I am saying is I have no anim sync issues at all, unless I introduce aim offset. I can even make separate idle anims for each corresponding aim offset pose and then in the extremes, I won’t have any anim sync issues. However, I still have sync issues when when going from one extreme to another. Not to mention I need to make more anims that used nowhere, but in aim offset.

Forget whoever told you whater BS about performance.
There’s simply no way that attaching a component costs more than running 2 sets of skeletal meshes. Ever. Particularly on mobile, where skeletal meshes need particular care.
Especially, when (if you read the docs about master pose component) the epic team expressly warns about performance concerns and promotes the mesh merge system.

You have the bones to animate the gun all included in the default skeleton. The weapon IK bones.
They can handle all the transitions and gun tricks you want.

They cannot handle stuff like slide checks, because to do that you need an extra bone for the slide, but normally that’s handled by the gun itself (attach the left hand IK to the slide bone that’s part of the gun and the characters animation will move it along.)

Last but not least.
You are running the gun on the same ABP (with same skeleton and same animations).
Are the gun bones of the AO the same or did you maybe forget to move them around?

If you test the AO on the gun only, does it seem like it moves as it should?
Even a slightly different offset will cause the calculated position to be off (which is why this whole double mesh is a particularly bad idea for weapons).

I don’t know about IK, because it’s just a single joint in the hand and in the holster. Nothing IK about it. I guess I can just attach component (static mesh gun) to socket (gun bone in the hand or in the holster) via anim notifies on specific frames.

Gun has exact same skeleton as character. All bones match 100%. I wouldn’t be able to use same skeleton asset for both and I wouldn’t be able to set it up as modular character if skeletons were different.

Gun has no AO. I am not sure how I’d set it up in the same animBP and I am not about to have different animBP for every single component in the modular character.
Is there a way to have AO for character for AO for gun in the same animBP ?

P.S. Speaking of performance of modular characters. It’s only worse than for non-modular character if one doesn’t use C++ code to merge parts. Based on the docs, modular is not slower than standard when you merge all that stuff via that C++ code block. I haven’t done that yet, but that’s the least of my concerns right now.

You are misinterpreting a lot of things (or making assumptions maybe).

  1. try to attach the gun to the IK bone.
    What happens?

Socketing to sockets is one thing. But sockets in a skeletal mesh also live on bones (hip for holster, usually).

  1. animate the IK bone.
    If the gun is attached to a socket on the IK bone. What happens?

  2. IK and the IK things have nothing to do with this. You are only hijacking the existing bones to do other things with. The fact you can also later on use the IK stuff is more of a happenstance.

  3. it really all depends on what bone the gun is painted on in the skeletal mesh.

And the skeletons don’t have to be identical since you could have additional bones on one that aren’t present on another provided the hierarchy is the same (so for performance you could remove the left side of the bones and both legs plus the head from the gun. For instance. Don’t go doing that yet, but it would work if you did).

What I’m asking is, if you test the IO using the gun mesh as the only mesh, where is the gun located? Does it move as it should or not?

If it doesn’t, then the assumption is that whatever bone it is painted to is not part of the bones that the AO alters.
The easy solution is to modify the poses of the AO to include the bone that handles the gun.

No, I haven’t tested it like that (at work right now and also I don’t have AO for the gun mesh itself).

I am not sure what you mean. AO poses for the character already include gun’s bone. Likewise, gun includes all of the bones character has. Although gun doesn’t have AO of its own.

If I make AO poses for the gun itself, how can I use AO for the gun in the animBP if it already has AO for the character? Should I just hook it up right after character’s AO in the Anim Graph ?

I’ll make a video for character setup in UE4 and also show animation software.

No, to merge the 2 you just set the position of all bones, including the gun ones, in the poses you use for the AO.

The end result needs to be that opening the AO and setting the preview mesh to the gun, the gun moves as you would expect it to (following invisible hands).
(Enable drawing all bones to debug).

Missing the position of the gun bone in a single frame could potentially shift the gun out of place in all frames because of the way the AO is calculated…

@MostHost_LA This is my character setup (and also how it looks in 3D animation app):

Look at the armor plates and breather device - they are modular, but don’t have any issues like pistol does. Those pieces and pistol are identical in every way (the setup and usage of AnimBP) except for one detail - pistol’s bone is a child of the root bone. Bones of the other pieces are children of whatever bones in the hierarchy they near by (spine, legs, etc.) - they aren’t directly parented to the root. Not sure if it’s relevant at all.

Yes well,
The root problem is in fact the parenting.

The position of the AO is a calculated differently because of that.
Your gun bone would need to be a child of the hand bone to get the AO working more correctly.

But.
Since this is what you have and you seem averse to doing the setup proper… (which you really should, there’s all sorts of reasons this setup is just bad…)

Why don’t you just throw a copy bone node in there and fix the position of the gun bone to the position of the hand bone?

This needs to happen after the AO for the position to be fixed, otherwise the AO may alter it again.

The benefit is that even though it isn’t socketed it will function as socketong would.
The downside is you still loose the specific gun bone animation.

Ofc, the bone copy could be active only while aming.

1 Like

The problem is that in the animation software I use, a bone that will be space-switched between other bones has to be (or at least what I understood) a child of the root bone. I am going to clarify that and if it can be a child of the hand, I’ll just fix it in the animation software.

What’s wrong with my setup ?

Because I have no clue what that is :slight_smile:

As I said, pretty much all of it.
From performance issues to a slur of other issues you would come about when you attempt to add IK to the gun if you ever did.
Plus issues animating the gun itself if you ever make one more complex like a revolver.

Well, that’s something you could very easily look up…
Animation Blueprint Copy Bone in Unreal Engine | Unreal Engine 5.3 Documentation.