Originally posted in UE4 Answers
I have a custom actor that I am wanting to interact with when I am next to it, like for a door. I created an overlay sphere component but both my begin and end overlap functions are being fired off at the same time, and when I exit the overlay just my end overlap function fires. I set them all up initially in C++; I did play around with them in the blueprints but I haven’t had any luck. Am I missing something? Here is the code I am using in my constructor to set everything up and the parent class of my object is an actor:
//Create RootComponent sceneComponent = ObjectInitializer.CreateDefaultSubobject<UBoxComponent>(this, TEXT("SceneComponent")); RootComponent = sceneComponent; overlaySphereComponent = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("OverlaySphereComponent")); overlaySphereComponent->SetSphereRadius(250.0f); overlaySphereComponent->AttachParent = RootComponent; overlaySphereComponent->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore); overlaySphereComponent->SetCollisionResponseToChannel(ECC_Pawn, ECollisionResponse::ECR_Overlap); overlaySphereComponent->OnComponentBeginOverlap.AddDynamic(this, &ABaseInteractObject::OnWorldOverlapBegin); overlaySphereComponent->OnComponentEndOverlap.AddDynamic(this, &ABaseInteractObject::OnWorldOverlapEnd);
I am using 4.7. Is anyone able to shed some light or did I go about this wrong?