UE4

‘ReceiveActorBeginOverlap’ marked ‘override’ but does not override any member functions – (Unreal Engine 4 with C++, Mac OSX)

Posted on Updated on

スクリーンショット 2015-09-20 21.15.00

After playing with Cocos2dx and Unity 5, I decided to challenge myself even further by working on a test project (FPS, 3rd person shooter etc) using Unreal Engine 4 with C++.

While working on a first person shooter project, I was in the middle of creating power up / health pick up items. All was going well until I ran into this error message:

‘ReceiveActorBeginOverlap’ marked ‘override’ but does not override any member functions

My source code below:

.h header file

    #pragma once
     #include "GameFramework/Actor.h"
     #include "HealthPack.generated.h"

    UCLASS()
    class TESTFPS_API AHealthPack : public AActor
    {
	    GENERATED_BODY()
	
    public:	
    	AHealthPack();	
	    AHealthPack(const FObjectInitializer& ObjectInitializer);	

	    virtual void 	BeginPlay()  override;
	    virtual void 	Tick( float DeltaSeconds ) override;
	    virtual void 	ReceiveActorBeginOverlap(class AActor* Other)	override;	

And in my .cpp implementation file l declare this method like this:

    void AHealthPack::ReceiveActorBeginOverlap(class AActor* Other)	
    {
     	if (Other != NULL)
	    {
	    	if (CanBePickedUp(Cast<ATestFPSCharacter>(Other)))
	    	{
	    		HandlePickUp(Cast<ATestFPSCharacter>(Other));
	    		HandleEffects();
	    		removeFromWorld();
	    	}
	    }
    }

Turns out that “ReceiveActorBeginOverlap” is not virtual so you cannot override this method (anymore). So to solve this you need to override <strong"NotifyActorBeginOverlap" and then call Super inside this function. Modifying the lines above to below resolves my error:

.h header file:

virtual void 	NotifyActorBeginOverlap(class AActor* Other)	override;

.cpp implementation file:

/**
 *	Check if we can pick up a health pack
 */
void AHealthPack::NotifyActorBeginOverlap(class AActor* Other)	
{
	Super::NotifyActorBeginOverlap(Other);

	if (Other != NULL)
	{
		if (CanBePickedUp(Cast< ATestFPSCharacter >(Other)))
		{
			HandlePickUp(Cast< ATestFPSCharacter >(Other));
			HandleEffects();
			removeFromWorld();
		}
	}
}