Download

Overlap Sphere Component

Hi,
I’m trying to convert this blueprint tutorial (https://www.youtube.com/watch?v=4yjcwZLQqlE)
to C++.
I have a collision sphere but I can’t trigger the overlap event.
This is my code:

header:


UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera)
USphereComponent* CollisionSphere;

UFUNCTION()
virtual void OnOverlapBegin(class UPrimitiveComponent* newComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

cpp



constructor

CollisionSphere = CreateDefaultSubobject<USphereComponent>("CollisionSphere");
	CollisionSphere->SetSphereRadius(90.0f);
	CollisionSphere->bGenerateOverlapEvents = true;
	CollisionSphere->SetupAttachment(RootComponent);
	CollisionSphere->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Overlap);
	CollisionSphere->bHiddenInGame = false;
	CollisionSphere->OnComponentBeginOverlap.AddDynamic(this, &AMelvinCppCharacter::OnOverlapBegin);


void AMelvinCppCharacter::OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
	GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("We got a collision."));
}


Can somebody help?
Thnaks.

Some times move the “AddDynamic” bind to BeginPlay may helps, and make sure you have “Generate Overlap Event” checed on both item.