Download

OnComponentBeginOverlap not firing

Hey folks,

I’m trying to set up a very basic Actor that responds to overlap events from player characters.

The actor itself is composed of two components: a sphere component and a static mesh.



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

UPROPERTY( VisibleAnywhere, BlueprintReadOnly, Category = Appearence )
UStaticMeshComponent*	PickupMesh;


In the constructor for the Actor I set up the basic collision callback:



CollisionSphere	= anObjectInitializer.CreateDefaultSubobject<USphereComponent>( this, TEXT("Collision Sphere") );
CollisionSphere->bGenerateOverlapEvents = true;
CollisionSphere->SetSphereRadius( INITIAL_SPHERE_RADIUS );
CollisionSphere->OnComponentBeginOverlap.AddDynamic( this, &MyClass::OnBeginOverlap );
RootComponent = CollisionSphere;
	
PickupMesh	 = anObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>( this, TEXT("Pickup Mesh") );
PickupMesh->AttachTo( RootComponent );

...


void MyClass::OnBeginOverlap( AActor* aCollidingActor, UPrimitiveComponent* anCollidingComponent, int32 anOtherBodyIndex, bool isFromSweep, const FHitResult& aSweepResult )
{
	GEngine->AddOnScreenDebugMessage( -1, 5.0f, FColor::Red, TEXT("OVERLAP!!") );
}


Then in the editor I have a blueprint derived from my simple class:

There’s an instance of the blueprint in my level, but I’m never getting any overlap events firing… any idea what might be causing this? I thought it might be because I set up the blueprint after adding the overlap callback, but I tried recreating the Blueprint and it produced the same result.

OnBeginOverlap should be a UFUNCTION ,so add UFUNCTION() before function declaration in .h file if not done already

Nailed it :slight_smile: Thanks!