Download

How do i fire event notifier in c++ ?

i’m making a base enemy_character, enemy_animInstance and enemy_AnimNotidy classes.
So i want to get the notify in my enemy_animInstance and fire it in the inhereted blueprint ( depends on the specific character animation ).
I’v tried using the code they give here:
Crash Course In Animation Notifies - Unreal Engine ( end of the page )
But it gives me a compile error ( unexpected public: something… ). is there a guide that shows me exactly how to do it?

Edit:
This is the error i get:

You probably forgot to implement the constructor in the .cpp file

UEnemy_Hit_Notifier::UEnemy_Hit_Notifier(const FObjectInitializer& ObjectInitializer /= FObjectInitializer::Get()/)
: Super(ObjectInitializer)
{
}

I’ve tried to put that in my cpp file and it still fives me similar error, can you show me please how the header and the source files supposed to look?

Anyone?..

Can you post your header and source files where the errors are occurring for us to look at?

Yep!

Header:


// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "Animation/AnimNotifies/AnimNotify.h"
#include "Enemy_Hit_Notifier.generated.h"

/**
 * 
 */
UCLASS()
class OLDSCHOOLNIGHTMARE_API UEnemy_Hit_Notifier : public UAnimNotify
{
	GENERATED_UCLASS_BODY()
	virtual bool Received_Notify(class USkeletalMeshComponent* MeshComp, class UAnimSequence* AnimSeq) const;


};


Cpp:


// Fill out your copyright notice in the Description page of Project Settings.

#include "OldSchoolNightmare.h"
#include "Enemy_Hit_Notifier.h"

UEnemy_Hit_Notifier::UEnemy_Hit_Notifier(const FObjectInitializer& ObjectInitializer /*= FObjectInitializer::Get()*/)
	: Super(ObjectInitializer)
{
}

GENERATED_UCLASS_BODY isn’t the recommended way to declare a constructor currently. See this thread.

I believe all you need to do is change that macro to GENERATED_BODY and then declare your constructor as usual.

Give this a shot:



// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "Animation/AnimNotifies/AnimNotify.h"
#include "Enemy_Hit_Notifier.generated.h"

/**
 * 
 */
// Theses shouldn't be needed since they are forward declared in AnimNotify.h
class USkeletalMeshComponent;
class UAnimSequence;
 
UCLASS()
class OLDSCHOOLNIGHTMARE_API UEnemy_Hit_Notifier : public UAnimNotify
{
	GENERATED_BODY()
	UEnemy_Hit_Notifier(const FObjectInitializer& ObjectInitializer);
	
	virtual bool Received_Notify(USkeletalMeshComponent* MeshComp, UAnimSequence* AnimSeq) const;
};

With this code in my header i get this error:

When changing to GENERATED_UCLASS_BODY() i get this error:

And after i remove “UEnemy_Hit_Notifier(const FObjectInitializer& ObjectInitializer);”
I get the same error as in the beginning:

Those errors are because you need to actually define ReceivedNotify in your cpp file.

i.e


bool UEnemy_Hit_Notifier::Received_Notify(USkeletalMeshComponent* MeshComp, UAnimSequence* AnimSeq) const
{
	// Fill with whatever custom code and return value.
	return true;
}

Cool! that and GENERATED_UCLASS_BODY() did the trick, i’m newb to c++ so these basic stuff are not so obvious to me :\ Thnaks!

Any idea why i can’t get this event inside my blueprint animation class like they show in this page?

Assuming things built correctly, your new Notify should appear under the “Native Notifies” section. If you haven’t restarted the editor since you got things compiling, you may want to do that.

It does appears over there, but when i go to the anim_bp graph, i can’t see it under the “add anim notify event” submenu ( RMB click ).