Getting overlapping objects/components in a UActorComponent

Hello,

I’m quite new to UE4. I am trying to create a simple game in order to understand how the engine works. I made my game using blueprints only but now I’d like to use c++ only.

In this game I have points (floating cubes) and a ball that the user controls.
I am trying to make the ball able to interact with a point so that when is overlaps with one, I update the user score and hide the cube.

I wanted to make this in a UActorComponent so that it can be reusable and added to any actor (the point being, using something else than an Actor that I already used to make the cubes float).
Here are my ball and points configuration regarding overlaps :

The HandlePoint component has “auto activate” checked

The problem is, I can’t get access to overlapping components in this. I have tried multiple solutions :

GetOwner()->GetOverlappingComponents(OverlappingComponents);
UE_LOG(LogTemp, Warning, TEXT(“Number of overlaps : %d”), OverlappingComponents.Num());

in UHandlePoint::TickComponent()
I always get 0 overlaps

I tried :
void UHandlePoint::BeginPlay()
{
Super::BeginPlay();
mesh = (UStaticMeshComponent*)(GetOwner()->GetComponentByClass(UStaticMeshComponent::StaticClass()));
mesh->OnComponentBeginOverlap.AddDynamic(this, &UHandlePoint::HandlePoint);
}

But my delegate never gets called.

I think I am missing something, either on C++ side or on editor side but I don’t know what

Hey flonou-

If the ball is meant to interact with the cube directly the the best option would be to set the Collision Presets for both the ball mesh and the cube mesh to Overlap each other. Looking at the screenshots the cube is set to NoCollision which means that overlap events won’t trigger for it (since there is no collision to overlap) and the ball is set to BlockAllDynamic which will stop the ball when it runs into any other dynamic actor before it begins to overlap. To only affect how these actors interact with each other you will want to create a new collision channel for each of them and, in the drop-down next to Collision Presets set the two to overlap each other. This should allow both actors to overlap one another and call any code associated with either of their BeginOverlap events.

Cheers

Indeed something was off here.
I have set the cube to “overlapAll”
and the sphere’s mesh component to physics actor as this is the configuration I have in the blueprint version that works.
Overlap + block triggers overlap

EDIT : my bad, the output log was stuck and I was not looking at the new logs, it’s working, thanks a lot !