Anim Notifies and Attaching Weapon

I am trying to attach my weapon at the point anim notify is active/hit in Montage. How can I cycle through the Montage and have weapon attached only at that point?

Current code is

// Play Montage
 PlayAnimMontage(RifleEquipMontage, 1, NAME_None);
// Attach Weapon
PrimaryWeaponToEquip->AttachToComponent(GetMesh(), FAttachmentTransformRules::SnapToTargetNotIncludingScale, RifleEquipSocketName);

which results in less than ideal Animation + Attachment

is there something like
if (Montage → AnimNotifyName = “NotifyName”)
Then Attach Weapon

It appears you have to create a new class derived from UAnimNotify and override

virtual void Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation) override;

I would have thought you could use OnPlayMontageNotifyBegin but the docs are lacking and I couldn’t get it to work by just trying different things :man_shrugging:.

yeah there’s not much out there.
I will have a look around with regards to UAnimNotify class and see how that goes.

just from the brief search I have done,
I have since created the new class

Header

CPP

I then attached the new notify class to my Montage

I am having trouble figuring out how to proceed at this point. I take it I don’t play the montage in my player character like I was doing before? And Weapon attachment will have to happen in the overridden Notify method?

I’m not quite sure how you have it set up before but I was assuming you would just play the montage and that notify would do the equipping by either doing it there or calling a function on the character.

This is how I currently have it set up
Montage is attached to my PlayerCharacter

Then my TogglePrimaryWeapon input has these lines

Turn line 135 into a function then from your notify class you can call it by getting the owner of the mesh and casting it to your character class.

1 Like

Did as you suggested and it works perfectly…

but :grinning:

I now noticed an issue with my montage on playback in editor. It crashes when it hits the notify. No issue when playing the game, but only when just trying to edit the montage. Kinda makes it a pain when trying to change or play around with the position of the notify to fine tune animation. Any idea what could be causing this? Its on the attachWeapon function I just created.

I would assume that is because the Owner is nullptr there. I’m not sure if there’s an editor only check you could use to avoid checking during play but a simple

if (GetOwner())

should solve it.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.