Game crashes when spawning two overlapping volumes on the same frame

Hello again answerhub! Here’s hoping someone can shed light on this problem.

I am getting a game crash when I spawn two collision volumes that start overlapping each other (each set to detect the other) and bind OnComponentOverlap.AddDynamic for each on the same frame. If not spawned at the same time, the crash does not occur. Can anyone tell me why this is happening?

The crash log tells me it is happening at or approximately around the line where I use AddDynamic. Please take a look and tell me if you have any ideas!

Update: Confirmed through some trial-and-error this is actually happening because I destroy the component if it overlaps another hitbox… I am currently assuming this is because I am destroying the component on the same frame AddDynamic is used. If anyone has any ideas for solutions or workarounds, let me know. In the mean-time I will try to see if I can delay the destruction by at least one frame and see if it still occurs.

Crash log

Relevant .h

// This is called when a hitbox component overlaps something.
	UFUNCTION()
		void OnHitboxOverlap(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

// The hitbox component. Currently there can only be one.
	UBoxComponent* BoxComponent;

Relevant .cpp

void AScuffleCharacter::OnHitboxOverlap(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
	if (!OtherComp || !OtherActor)
	{
		return;
	}
	
	if (OtherActor == this)
	{
		return;
	}
	
	//For each thing we collided with, perform actions based on its type.
	
	if (OtherComp->GetCollisionObjectType() == ECollisionChannel::ECC_GameTraceChannel1)
	{
		//Hitbox is colliding with another hitbox.
		AScuffleCharacter* OverlappedCharacter = Cast<AScuffleCharacter>(OtherActor);
		if (OverlappedCharacter)
		{
			//Destroy both character's hitboxes, they cancel each-other out.
			OverlappedCharacter->DestroyHitbox();
			DestroyHitbox();
		}
	}
}

void AScuffleCharacter::SpawnHitbox(FVector Offset, FVector Size)
{
	DestroyHitbox();
	BoxComponent = NewObject<UBoxComponent>(this, UBoxComponent::StaticClass());
	if (BoxComponent)
	{
		BoxComponent->RegisterComponent();
		BoxComponent->PrimaryComponentTick.bRunOnAnyThread = false;
		BoxComponent->AttachToComponent(GetRootComponent(), FAttachmentTransformRules::SnapToTargetIncludingScale, NAME_None);
		if (bIsFacingRight)
		{
			BoxComponent->SetRelativeLocation(Offset);
		}
		else
		{
			BoxComponent->SetRelativeLocation(-Offset);
		}
		BoxComponent->SetBoxExtent(Size);
		BoxComponent->SetHiddenInGame(bShouldHideHitboxes);
		BoxComponent->SetCollisionProfileName(FName("Hitbox"));
		BoxComponent->OnComponentBeginOverlap.AddDynamic(this, &AScuffleCharacter::OnHitboxOverlap);
		BoxComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision);
		BoxComponent->SetCollisionEnabled(ECollisionEnabled::QueryOnly); // Don't know why, but toggling this updates overlaps
	}
}

void AScuffleCharacter::DestroyHitbox()
{
	if (BoxComponent)
	{
		BoxComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision);
		BoxComponent->OnComponentBeginOverlap.RemoveDynamic(this, &AScuffleCharacter::OnHitboxOverlap);
		BoxComponent->DestroyComponent();
		BoxComponent = NULL;
	}
}