How to get actor for IsOverlappingActor?

Hello!

I’m trying to make my character/enemy able to recognize objects with which they collided.

FPSEnemy recognize when it collides with Character, but FPSCharacter is not recognize when it collides with Enemy. Is there any way to get Enemy actor for IsOverlappingActor?

FPSEnemy.cpp

void AFPSEnemy::OnOverlapBegin(UPrimitiveComponent * OverlappedComp, AActor * OtherActor, UPrimitiveComponent * OtherComp,
	int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
	AFPSCharacter* playerOverlap = Cast<AFPSCharacter>(GetWorld()->GetFirstPlayerController()->GetCharacter());
	if (IsOverlappingActor(playerOverlap))
	{
		GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Green, TEXT("Enemy's overlap is working"));
	}
}

FPSCharacter.cpp

void AFPSCharacter::OnOverlapBegin(UPrimitiveComponent * OverlappedComp, AActor * OtherActor, UPrimitiveComponent * OtherComp,
	int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
	AFPSEnemy* enemyOverlap = Cast<AFPSEnemy>(GetWorld()); // ?????
	if (IsOverlappingActor(enemyOverlap))
	{
		GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Green, TEXT("Player's overlap is working"));
	}
}

Why you call IsOverlappingActor() at all, thats a second Overlap Check? OtherActor is the thing you overlapped.

     AFPSEnemy* enemy = Cast<AFPSEnemy>(OtherActor);
     if (enemy)
     {
         GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Green, TEXT("Overlapped a Enemy"));
     }

Same for the Enemy.

But how can I use this with many actors that can be overlapped? Because if I try to change some variables in class that is not OtherActor, I will have an engine crash.

Honest advise: Pick up a C++ book =)

Dont change AActor* OtherActor ever in the Function. You cast to the class you want to use or use Interfaces or planty of other things you could do. I´m not going to explain you the fundamentals here sorry =( thats to much to Ask.