ShapeComponent doesn't return anything using Get overlapping actors C++

I cant get GetOverlappingActors to return anything

I spawned two boxes (actors) with ShapeComponent* then i call this function
A function that adds a boxComponent

UboxComponent* boxComponent =NewObject<UBoxComponent>(this, TEXT("");
ShapeComponent=boxComponent;
ShapeComponen->SetGenerateOverlapEvents(true);
ShapeComponent->RegisterComponent();

Note For some reason i cannot add this to the constructor

Now i can see the boxs in the game when the game is running, but when I create 2 boxes next to each other and i call GenerateOverlappingActor on each tick I get nothing

Also note that i set the box extents and i can see that the two boxes overlapping

I used GenerateOverlapping actors on the ShapeComponent and on the actor both cases return nothing

Any idea whay could be the reason behind this?!!!

I will assume that you didn’t copy and paste your actual code because the above has syntactical errors (UBoxComponent, ShapeComponent->SetGenerateOverlapEvents(true);).

In any case, have you tried adding them as components using:
BoxComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("My Box"));
This can go in your constructor. Then you should be able to use GetOverlappingActors in Tick (or better still, use a Dynamic Delegate so you don’t run unnecessary processes on your Tick). Here is an example:

//In your constructor:
BoxComponent->OnComponentBeginOverlap.AddDynamic(this, &AMyActor::OnOverlapBegin);

//Then in your class add

void AMyActor::OnOverlapBegin(class UPrimitiveComponent* OverlappingComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
    //react to event here
}

Of course replace ‘AMyActor’ with your class name.

Yes, i wrote it on my phone, :slight_smile:

No it won’t work, createdefaultsubobject works only in the constructor and i am not creating this component there as mentioned in my OP, i am creating after the object is spawned.

Im such cases You should use NewObject instead, if you are not making the component in the constructor( also note that I could be wrong because I am new to Unreal Engine, so maybe double check thatI just fixed it, The issue i had was with the profiler, it was set to block all instead of overlap

I see. I didn’t realise you didn’t want it in the constructor. All good, glad you found the solution.