Here’s my situation. I’m trying to have a base parent class (UsableActor) and a child class that extends from it (UsableActorActivator)
I need UsableActor to have a function called OnUsed, and I need UsableActorActivator to override this function.
However, I want to be able to create a child blueprint of UsableActorActivator and a create an event of OnUsed, to add more functionality content wise. I’m aware that BlueprintNativeEvent is where I should be looking at, but not sure exactly how to use it.
How would this sort of function be set up? I’m always getting some sort of compilation error when trying to do it, so it’d be nice to see a correct implementation of it if possible.
#include "AH501041.h"
#include "UsableActor.h"
AUsableActor::AUsableActor()
{
PrimaryActorTick.bCanEverTick = true;
}
void AUsableActor::BeginPlay()
{
Super::BeginPlay();
// This is the "event" OnUsed is being called at
// Normally, this would be done at the actual interaction event
// up to you to change how this works.
OnUsed( );
}
void AUsableActor::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}
void AUsableActor::OnUsed_Implementation( )
{
OnUsedInternal( );
}
// Because BlueprintNativeEvent can't be virtual, have the native event call a virtual function.
// This allows child class to override virtual for different / additional functionality.
void AUsableActor::OnUsedInternal( )
{
UE_LOG( LogTemp, Warning, TEXT("AUsableActor: %s"), *GetName( ) );
}
As you can see the UsableActorActivator inherits whatever functionality that UsableActor has inside of “OnUsedInternal”. This should give you the freedom to either override completely or take on functionality in the child class.