I have an actor with a sphere component that I use for tracking Pawns within the sphere. All is well when a Pawn enters the sphere: OnBeginOverlap is triggered and OnEndOverlap is triggerred when it exists, but when a new pawn is spawned inside the sphere then neither is triggered. Only when the pawn leaves the sphere the OnBeginOverlap is triggered the next time it re-enters. Has anyone encountered it and does anyone know a way to make it trigger the OnBeginOverlap even when an actor is spawned inside it? Below the related code of the tracking actor.
Creating the sphere in constructor:
// Sphere for pawn tracking
RespawnSphere = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("RespawnSphere"));
RespawnSphere->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
RespawnSphere->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
RespawnSphere->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Overlap);
RespawnSphere->ShapeColor = FColor::Green;
RespawnSphere->AttachTo(RootComponent);
Initializing the sphere in actor’s OnConstruction:
RespawnSphere->SetSphereRadius(RespawnRadius);
RespawnSphere->OnComponentBeginOverlap.AddUniqueDynamic(this, &APortStructure::OnBeginOverlap_RespawnSphere);
RespawnSphere->OnComponentEndOverlap.AddUniqueDynamic(this, &APortStructure::OnEndOverlap_RespawnSphere);
The functions that should be called:
void AMyActor::OnBeginOverlap_RespawnSphere(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool Something, const FHitResult& HitResult)
{
// Do something
}
void AMyActor::OnEndOverlap_RespawnSphere(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
// Do something
}