I did exactly as in the Unreal Wiki, yet it will not call the function for me.
To check that it was not my collision settings I did the function in blueprints and it worked just fine.
I also tried using OnActorBeginOverlap instead of OnComponentBeginOverlap, does not work either.
Header:
class THEMAZEFPSPROTO_API AThrowableBase : public AInteractableActor
{
GENERATED_BODY()
public:
AThrowableBase();
void Initialize(float InitialSpeed);
virtual void OnOverlapBegin(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
private:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
USphereComponent* CollisionSphere;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
UProjectileMovementComponent* ProjectileMovement;
};
Source:
AThrowableBase::AThrowableBase(){
CollisionSphere = CreateDefaultSubobject<USphereComponent>(TEXT("CollisionSphere"));
ProjectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileMovement"));
RootComponent = CollisionSphere;
CollisionSphere->OnComponentBeginOverlap.AddDynamic(this, &AThrowableBase::OnOverlapBegin);
}
void AThrowableBase::Initialize(float InitialSpeed){
ProjectileMovement->InitialSpeed = InitialSpeed;
}
void AThrowableBase::OnOverlapBegin(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult){
GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Red, FString::Printf(TEXT("Ouch")));
OtherActor->Destroy();
}