Hello,
I have attached a collisionbox to an Actor and everytime my character is colliding with it i am creating a new floor tile but it only works on the first collisionbox.
here is my code :
void AFloor::BeginPlay()
{
Super::BeginPlay();
Collisionbox->OnComponentBeginOverlap.AddDynamic(this,&AFloor::CheckCollision);
}
void AFloor::CheckCollision(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if ((OtherActor != nullptr) && (OtherActor != this) )
{
SpawnFloor(); // here i spawn a Bluepring floor tile actor
}
}
Collisionbox->OnComponentBeginOverlap.AddDynamic(this,&AFloor::CheckCollision);
Move this section of the code to the constructor and add an keyword virtual infornt of your check collision function in the .h file
Well by default i don’t know why but if your function does not have the name OnOverlapBegin() the function does not get a call. But adding the virtual keyword lets you overide that as well as helps if you are going to create a child class.