How would I get a reference to the mesh an animation Notify is firing on?

I have a subclass of UAnimNotify which needs to do a sweep test starting from an arbitrary socket. Getting the transform to center the test on seems pretty trivial:

FTransform SetHitboxLocation(FString targetBone){
	ACharacter* myCharacter;
	FTransform desiredLocation = myCharacter->GetMesh()->GetBodyInstance(targetBone)->GetUnrealWorldTransform();
	return desiredLocation;
}

However, animation notifies don’t live on the ACharacter like a component, they exist somewhere in UE4’s ether and only get called when you set them up in Persona. To that end, is there a way I can get a reference to the character or mesh whose animations are triggering the notify?

Oooh, I think this might work perfectly- it has one error right now, though, which I’m having a little trouble parsing. This is the complete code:

void UHitframeNotifyState::NotifyTick(USkeletalMeshComponent * MeshComp, UAnimSequenceBase * Animation, float FrameDeltaTime){
	hitboxTransform = SetHitboxLocation(hitboxBoneName, MeshComp);
}
FTransform SetHitboxLocation(FString boneName, USkeletalMeshComponent* MeshComp){
	FTransform desiredLocation = MeshComp->GetBodyInstance(FName(*boneName))->GetUnrealWorldTransform();
	return desiredLocation;
}

And this is the error it produces:
""Error HitframeNotifyState.cpp.obj : error LNK2019: unresolved external symbol “public: struct FTransform __cdecl UHitframeNotifyState::SetHitboxLocation(class FString,class USkeletalMeshComponent *)” (?SetHitboxLocation@UHitframeNotifyState@@QEAA?AUFTransform@@VFString@@PEAVUSkeletalMeshComponent@@@Z) referenced in function “public: virtual void __cdecl UHitframeNotifyState::NotifyTick(class USkeletalMeshComponent *,class UAnimSequenceBase *,float)” (?NotifyTick@UHitframeNotifyState@@UEAAXPEAVUSkeletalMeshComponent@@PEAVUAnimSequenceBase@@M@Z)
"

What about:

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

You can obtain within Notify event your MeshComp(owner of the animation and notify)
And if you want to get a pawn reference just call
MeshComp->GetOwner() and try cast it to your character or something.

Regards

Pierdek

I’ll suggest make SetHitboxLocation as a member of class UHitframeNotifyState
but if you want to leave it as global put it before UHitframeNotifyState::NotifyTick in the code.

…so I cannot believe I did that, this is like the fifth time in as many days I’ve had a weird, unexplained error that was caused by me forgetting to scope the function properly. It works now, thank you so much!! This has been bothering me for well over a week :slight_smile: