Download

How to overlap the class of an object in C ++?

I want to add the function of adding weapons on key press But when overlap, the class of the object is not defined.

Code:
APlayerCharacter::APlayerCharacter()
{

TriggerCapsuleComponent = CreateDefaultSubobject<UCapsuleComponent>(TEXT(“TriggerCapsule”));
TriggerCapsuleComponent->InitCapsuleSize(55.f, 96.0f);;
TriggerCapsuleComponent->SetCollisionProfileName(TEXT(“OverlapAll”));
TriggerCapsuleComponent->SetupAttachment(RootComponent);

TriggerCapsuleComponent->OnComponentBeginOverlap.AddDynamic(this, &APlayerCharacter::OnOverlapBegin);
TriggerCapsuleComponent->OnComponentEndOverlap.AddDynamic(this, &APlayerCharacter::OnOverlapEnd);

}

void APlayerCharacter::OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (OtherActor && (OtherActor != this) && OtherComp)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, OtherActor->GetName());
}
}

void APlayerCharacter::OnOverlapEnd(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
if (OtherActor && (OtherActor != this) && OtherComp)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, OtherActor->GetName());
}
}

Maybe SetCollisionProfileName is not set correctly? Then what kind of collision should you choose?