I can’t make USphereComponent generate overlap events in C++. I was folowing several tutorials and nothing works. Here is one of them that I used: https://unrealcpp.com/on-overlap-begin/.
I copied code from there and it still doesn’t work.
Here is the code:
UEnvironmentContextSystem::UEnvironmentContextSystem()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;
SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComponent"));
SphereComponent->SetSphereRadius(300);
SphereComponent->SetCollisionProfileName(TEXT("Trigger"));
SphereComponent->SetupAttachment(GetOwner()->GetRootComponent());
// ...
}
// Called when the game starts
void UEnvironmentContextSystem::BeginPlay()
{
Super::BeginPlay();
SphereComponent->OnComponentBeginOverlap.AddDynamic(this, &UEnvironmentContextSystem::OnOverlapBegin);
SphereComponent->OnComponentEndOverlap.AddDynamic(this, &UEnvironmentContextSystem::OverlapEnd);
// ...
}
// Called every frame
void UEnvironmentContextSystem::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// ...
}
void UEnvironmentContextSystem::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
UE_LOG(LogTemp, Warning, TEXT("OVERLAP START %s"), *OtherActor->GetName());
}
void UEnvironmentContextSystem::OverlapEnd(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
UE_LOG(LogTemp, Warning, TEXT("OVERLAP END"));
}