Why pawn is not other actor while overlapping in C++?

Hi, I am overlapping a box collision so its mean I the pawn is other actor, but checking this is always failed as in the example I will show.

This always print Overlap Failed

void AMyTestClass::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
	if (OtherActor == CharacterRef) //CharacterRef is a direct * refference to the MyBaseCharacterClass
	{
		printf("OverLapped Passed");
	}
		printf("OverLap Failed");
}

at the same time doing this in blueprints is not failing and overlapped passed.
This always print Overlap Item Passed

Checking with
if (OtherActor == this) //also failed always , logically it should not get failed because this is also defining the current actor which is overlapping is character.

the nature of blueprints is many things are goin on behind the scenes, in your bp script that

== is not using the straight if(…){…} , I think some dynamic casting is happenin behind the scene to compare actor and character , create a native code of your script and check if it will help you to see how and when the casting is occured.
or try to store the result in a bool comparing actor and character on dynamic casting and then check that bool in under if statement…

Hope it helped you.

1 Like

nice trick, I will look into this, Thank You Sir very much for suggestion :slight_smile:

Just out of curiosity: is it printing both “Overlapped Passed” and “Overlap Failed”?

Hi, Nope it just print Overlap Failed.