Can I change a sockets tranform in runtime?

I am (still) working on a FPS game the problem is in getting the gun attached to the pawn mesh’s hand.

What I have done so far is made animations using a dummy gun in Blender but it wont fit correctly in the engine because the origin for the gun is different from the dummy and this will mean making separate animations for each gun.

What can be done however is if I could simply make a set transforms for the sockets which keeps each gun in place instead of correcting the animation again and again I would just apply the adjusted socket position .

I do not see any set transform function for the bone socket however the socket fields for rotation ,scale and location are public. is that the way to do it?

Well I’m pretty familiar with the IK system for gun and hand placement, My question is how do i make it for different guns? Different guns may have different meshes hence different origins and handle location. since the mesh snap to socket by origin There will be a need to adjust the socket location for each gun otherwise you;ll need to shift the pivot points of each gun

First of all - are you sure you want to do that from code? If yes, then ignore what’s coming next.

Usually you’d set up your socket offset so that the handle of the gun is located where it supposed to be:

This will make sure that your right hand (the one holding the weapon) will always have correct placement, when animated. As for the left hand, you should use IK to place it in the right spot:

31318-ik.png

And drive the alpha parameter with a curve. You can control where you want your IK to be on or off directly on the animation asset:

This setup will work for pistols, rifles, shotguns and etc. You will need to do some tweaking to IK effector locations of course (for pistols it is goinh to be near the grip, for rifles and shotguns near the forestock and etc.) but overall you will be able to have a singe general set of animations of standing, running, jumping to work with several types of guns.

If you need more details - just let me know.

You usualy do it this way for realy different types of weapons. You end up having a socket for one-handed weapons, two-handed weapons, rocket launchers and etc. It’s a valid setup.

And mesh snaps not by its origin but the position of its root bone if we’re talkign about SkeletalMeshes (which weapons usualy are). And its up to you to place this root bone in the right location in your DCC package.

Goddamnit! Why am I so Stupid?

all I needed to do was use the gun as a child actor component with a scene as root and mesh as its child. and you can now move the mesh anywhere you want.

Bloody Hell…

1 Like

where did my answer go?