BeginOverlap event, check if Actor is certain class type

My BeginOverlap method:

void UWall::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResul) {
	if(OtherActor) {
		// Check if OtherActor is a USpaceBall class
		UE_LOG(LogTemp, Warning, TEXT("A"));
		if(OtherActor->IsA(USpaceBall::StaticClass())) {
			UE_LOG(LogTemp, Warning, TEXT("B"));
		} else {
			UE_LOG(LogTemp, Warning, TEXT("C"));
		}
	}
}

This event fires up when a SpaceBall actor overlaps a UWall actor.

I always see message A and C in the console.

This is the info I get when debugging about OtherActor argument:

try

Cast<USpaceBall>(OtherActor) != nullptr

Same result.

Your other actor is an actor spaced ball, does it inherit from USpaceBall. Can you show us this code/BP

any way you can share the project or parts of the project,
Cast(OtherActor) != nullptr should work

Hey there, I think I’m confusing definitions and that’s why maybe I’m doing these things in the wrong way, this is how it looks my actor in the scene.

If I understand correctly now, is my actor just an actor that has a USpaceBall component (ActorComponent) in it?

The following code works because now I’m checking against the USpaceBall component.

USpaceBall* spaceBallComponent = reinterpret_cast<USpaceBall*>(OtherActor->GetComponentByClass(USpaceBall::StaticClass()));
if(spaceBallComponent) {
    if(OtherActor == spaceBallComponent->GetOwner()) {
        UE_LOG(LogTemp, Warning, TEXT("Working"));
    }
}

oopsly, never read the U in USpaceBall
yeah that’s just a component and you have to test for that

I was thinking that your objects inherits from ASpaceBall and then the whole actor is a subclass of that and can be casted to.