Hey I am trying to detect the items in a cube. However, the overlap begin and overlap end function calls are not making sense.
Here is my cpp:
ALocationBox::ALocationBox()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
Cube = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("mesh"));
RootComponent = Cube;
static ConstructorHelpers::FObjectFinder<UStaticMesh> BoxAsset(TEXT("/Game/StarterContent/Shapes/Shape_Cube"));
if(BoxAsset.Succeeded()){
Cube->SetStaticMesh(BoxAsset.Object);
Cube->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));
Cube->SetWorldScale3D(FVector(1.f));
}
Cube->SetCollisionProfileName(TEXT("OverlapAll"));
Cube->OnComponentBeginOverlap.AddDynamic(this, &ALocationBox::OnOverlapBegin);
Cube->OnComponentEndOverlap.AddDynamic(this, &ALocationBox::OnOverlapEnd);
}
//Overlap does not seem to be working judging from testing
void ALocationBox::OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (OtherActor && (OtherActor != this) && OtherComp)
{
UE_LOG(LogTemp, Error, TEXT("Began overlap with: %s"), *OtherActor->GetName());
}
}
void ALocationBox::OnOverlapEnd(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
if (OtherActor && (OtherActor != this) && OtherComp)
{
UE_LOG(LogTemp, Error, TEXT("Ended overlap with: %s"), *OtherActor->GetName());
}
}
I placed a peeler, cutting board, knife and coffer maker in the box. Here is the output:
[2020.03.27-05.17.26:600][426]LogTemp: Error: Ended overlap with: Board
[2020.03.27-05.17.26:600][426]LogTemp: Error: Ended overlap with: Board
[2020.03.27-05.17.26:600][426]LogTemp: Error: Ended overlap with: Knife
[2020.03.27-05.17.26:600][426]LogTemp: Error: Ended overlap with: Knife
[2020.03.27-05.17.26:600][426]LogTemp: Error: Ended overlap with: Knife
[2020.03.27-05.17.26:621][426]LogTemp: Error: Ended overlap with: Knife
[2020.03.27-05.17.26:622][426]LogTemp: Error: Ended overlap with: Peeler
[2020.03.27-05.17.26:622][426]LogTemp: Error: Ended overlap with: Peeler
[2020.03.27-05.17.26:622][426]LogTemp: Error: Ended overlap with: Peeler
No overlap began detection occurred. The items were never removed from the box.
Thanks in advance.