Download

OnOverlapBegin works but not OnOverlapEnd

Hello,

I am having hard time with OnOverlapEnd. OnOverlapBegin works, and if I leave the area then come back, i can see through logger that collision occurred again, so I am assuming that at some point the Overlap has ended.

In my actor I have:

Header file in public section


	UFUNCTION()
	virtual void OnOverlapBegin(class UPrimitiveComponent* newComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

	UFUNCTION()
	virtual void OnOverlapEnd(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);


In actor constructor I have:


	// Enable the generation of overlapping events and assign a function to be run when it happens.
	COllisionComp->bGenerateOverlapEvents = true;

//	COllisionComp->OnComponentBeginOverlap.AddDynamic(this, &ATV1::OnOverlapBegin);
	COllisionComp->OnComponentEndOverlap.AddDynamic(this, &ATV1::OnOverlapEnd);

Note that even if I uncomment the BeginOverlap, I still get BeginOverlap to work!!

In the collision functions for actor:


void ATV1::OnOverlapBegin(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
	// OtherActor is the actor that triggered the event. Check that is not ourself
	if ((OtherActor == nullptr) || (OtherActor == this) || (OtherComp == nullptr))
		return;
	
	UE_LOG(MyLog, Warning, TEXT("COllision"));
}


void ATV1::OnOverlapEnd(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
	UE_LOG(MyLog, Warning, TEXT("Calling end overlap"));
	// OtherActor is the actor that triggered the event. Check that is not ourself
	if ((OtherActor == nullptr) || (OtherActor == this) || (OtherComp == nullptr))
		return;
	UE_LOG(MyLog, Warning, TEXT("End COllision"));
}

So, in summary, there are two problems:

The first problem:
OnOverlapEnd is not called although I can see OnOverlapBegin called multiple times

The second problem:
Even if I comment out the following line, OnOverlapBegin is still called.



//	COllisionComp->OnComponentBeginOverlap.AddDynamic(this, &ATV1::OnOverlapBegin);

Any help is appreciated.

Ok, I got it. I just needed to take a break it seems.

Moving the following code to BeginPlay() from constructor solved the problem:

<


    // Enable the generation of overlapping events and assign a function to be run when it happens.
    COllisionComp->bGenerateOverlapEvents = true;

//    COllisionComp->OnComponentBeginOverlap.AddDynamic(this, &ATV1::OnOverlapBegin);
    COllisionComp->OnComponentEndOverlap.AddDynamic(this, &ATV1::OnOverlapEnd);  

However, now I get the following errors when I hit “Play”

I am getting run time error, but I moved the add dynamic bindings to BeginPlay().

I get:
LogOutputDevice:Error: === Handled ensure: ===
LogOutputDevice:Error: Ensure condition failed: InvocationList CurFunctionIndex ] != InDelegate [File:C:\Program Files (x86)\Epic Games\4.13\Engine\Source\Runtime\Core\Public\UObject\ScriptDelegates.h] [Line: 503]
LogOutputDevice:Error: Stack:
LogOutputDevice:Error: UE4Editor-Core.dll!FWindowsPlatformStackWalk::StackWalkAndDump() [d:\build++ue4+release-4.13+compile\sync\engine\source\runtime\core\private\windows\windowsplatformstackwalk.cpp:183]
LogOutputDevice:Error: UE4Editor-Core.dll!FDebug::EnsureFailed() [d:\build++ue4+release-4.13+compile\sync\engine\source\runtime\core\private\misc\outputdevice.cpp:297]
LogOutputDevice:Error: UE4Editor-Core.dll!FDebug::OptionallyLogFormattedEnsureMessageReturningFalse() [d:\build++ue4+release-4.13+compile\sync\engine\source\runtime\core\private\misc\outputdevice.cpp:432]
LogOutputDevice:Error: UE4Editor-virtualarty-4644.dll
LogOutputDevice:Error: UE4Editor-virtualarty-4644.dll
LogOutputDevice:Error: UE4Editor-virtualarty-4644.dll
LogOutputDevice:Error: UE4Editor-Engine.dll!AActor::BeginPlay() [d:\build++ue4+release-4.13+compile\sync\engine\source\runtime\engine\private\actor.cpp:2993]

There is a debug check in editor to prevent the same function from an object binding to an event like OnOverlapEnd. So you need to make sure that the function from that object instance is bound only once. Or, you could call RemoveDynamic with the same parameters before AddDynamic. You can also query to see if a member function of an instance is already bound to an event.