Hi! I’m experimenting with c++ in unreal and trying to figure out the best way to program in an overlap event.
So far, I have the overlap functioning, but now I’m at the stage where I want to the overlap to identify the other actor and run a function. The problem being, im unsure how to properly cast in this situation. My current code functions as such:
#include "ShooterCharacter.h"
void ACoin::OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
AShooterCharacter* tmp = Cast<AShooterCharacter>(OtherActor);
tmp->AddCoin();
this->Destroy();
}
As you can see, it casts the other actor to the class I want to identify, and then attempts to run a function on said actor. To do this, I have to include the header file for the actor, which feels wrong. Is this the correct way to do this or is there some other method I’m missing.
Any advice would be appriciated!