Hello,
I’m new to C++ (and have like 2 days of experience using it)
I would like to recreate something as simple as overlapping an actor with the base character’s CapsuleComponent.
The overlapped actor only has a StaticMesh as root component.
And the Character doesn’t have any extra components.
It’s easy in BP, but in C++ I tried to use this in the Base Character class.
.h
public:
UFUNCTION()
void OnPickupOverlap(UPrimitiveComponent* OnComponentBeginOverlap, UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
.cpp
//constructor
GetCapsuleComponent()->OnComponentBeginOverlap.AddDynamic(this, &ThisClass::OnPickupOverlap);
void ACPPtrainCharacter::OnPickupOverlap(UPrimitiveComponent* OnComponentBeginOverlap, UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (AMyCPPActor* MyActorPtr = Cast<AMyCPPActor>(OtherActor))
{
MyActorPtr->Destroy();
}
}
MyCPPActor is set with
.cpp
MeshComp = CreateDefaultSubobject<UStaticMeshComponent>;
RootComponent = MeshComp ;
MeshComp->SetCollisionProfileName("OverlapAll", true);
MeshComp->SetGenerateOverlapEvents(true);
.h
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UStaticMeshComponent* MeshComp;
And I can’t get it to work at all… the overlap events never trigger.
I think I need help with this.