Crash second time an actor spawn

I’m trying to create dynamic tiles for an endless runner game. I have a mastertile class which have a mesh and arrow component and I have created bp ver of this class that is the tile im going to use in-game .my problem is when I pass collision box for the first time It creats a tile perfectly but if I pass for a second time my game crash as stack overflowed and i have no idea why that is as it should simply create another tile on same exact location as last one.

UFUNCTION()
void AMasterTile::OnOverlapBegin(UPrimitiveComponent * OverlappedComp,
	AActor * OtherActor, UPrimitiveComponent * OtherComp,
	int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
	AMistakeCharacter* Hero = (AMistakeCharacter*)OtherActor;
	if (OtherActor == Hero) 
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Overlap Begin"));
	    FVector location = this->arrow->GetComponentLocation();
		GetWorld()->SpawnActor(this->GetActorClass(), &location);
			
	}
}

Hi there,

A StackOverflow error means you fill up all space on the Heap.
What I think it’s happening is:

  1. The player triggers the OnOverlapBegin
  2. You spawn a tile at the arrow’s position.
  3. The player triggers the OnOverlapBegin on the second tile.
  4. You spawn a tile at the arrow’s position again, which has not been modified. So you spawn the third tile directly under the second one
  5. The player triggers the OnOverlapBegin on the third tile instantly because it’s in the same place
  6. You enter an infinite loop of spawning over the second tile and triggering more spawns.
  7. This fills the heap and gets your error.

Try to move the arrow component after each spawn.

but those two arrows are far from each other this will never happen(The player triggers the OnOverlapBegin on the second tile.)

look if i move as i should in runner game it would not crash but if i turn it suddenly crash