Changing the position of a static mesh (weapon) attached to a socket when animation state changes

Hi. I was just wondering if anyone knew of a method to set a static mesh (rifle) into position depending on the animation state that is playing.
What I want is for the rifle to be pointed down in a way that is consistent with the Idle position. This is a different rifle position from when the character is moving forward (the rifle is also pointing fwd).

What I have done is the following:

I have a Mixamo character that is in a character blueprint.
The animations associated with the character are Rifle_Walk, Rifle_Run and Rifle_Idle. These have also been downloaded from Mixamo.
There’s a state machine in an animation blueprint.

The character has a socket attached to its right hand.

In the character blueprint i added a static mesh, set it to the rifle, set the parent socket correctly and then rotate and moved the weapon into place (the rifle is pointing forward).

But when the state changes to Rifle_Idle the weapon is still in the same position as it was set for Rfile_Walk/Run.

Trying to figure out how to change the Rifle position based on the animation.


One approach would be use an animation notify event that gets fired when the appropriate animation state is playing. This notify event creates an event node in your animation blueprint event graph and from this event node you can get the player and then the weapon and set the weapon transform accordingly. Keep in mind if you did this you would also need another notify event doing much the same thing for when the animation changes back to the other animation state.