I have configured an actor to be overlapped.
Here the code:
MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComp"));
MeshComp->SetCollisionEnabled(ECollisionEnabled::NoCollision);
RootComponent = MeshComp;
SphereComp = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComp"));
SphereComp->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
SphereComp->SetCollisionResponseToAllChannels(ECR_Ignore);
SphereComp->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
SphereComp->SetupAttachment(MeshComp);
In the Tick method I call the GetOverlappingComponents
to get the components that overlap but it always return an empty array.
The tick method code:
void ASphereDestroyer::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
TArray< UPrimitiveComponent *> Components;
SphereComp->GetOverlappingComponents(Components);
if (GEngine) {
if (Components.Num() > 0)
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, FString::FromInt(Components.Num()));
}
}
I use the DebugMessage for testing purpose and it doesn’t show on screen.
Both the actors have the Generate Overlap Events
set to true.