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:
Initializing the sphere in actor's OnConstruction:
The functions that should be called:
Creating the sphere in constructor:
Code:
// 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);
Code:
RespawnSphere->SetSphereRadius(RespawnRadius); RespawnSphere->OnComponentBeginOverlap.AddUniqueDynamic(this, &APortStructure::OnBeginOverlap_RespawnSphere); RespawnSphere->OnComponentEndOverlap.AddUniqueDynamic(this, &APortStructure::OnEndOverlap_RespawnSphere);
Code:
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 }
Comment