Binding OnActorBeginOverlap function issue

I am having an issue where binding the OnActorBeginOverlap in the constructor isn’t working. I don’t know if I missed something in the parameters or what?! DISCLAMIER I took out a chunk of code that shouldn’t affect it and so it would be easier to debug, but this is a simple projectile actor that I’m making for anybody asking.

header:

UCLASS(abstract)
    class PLANETARYPORTALS_API ABlast : public AActor
    {
    	GENERATED_BODY()
    	
    public:	
    	// Sets default values for this actor's properties/CONSTRUCTOR
    	ABlast();
    
    protected:
    
    	/*-----------Method/Function Declaration-------------*/	
    
    	//This is the function I'm using.
    	void BeginOverlap(class AActor* OtherActor);
    }

source:

 // Sets default values
    ABlast::ABlast()
    {
     	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    	PrimaryActorTick.bCanEverTick = true;
    
    	InitialLifeSpan = 2.0f;
    
    	OnActorBeginOverlap.AddDynamic(this, &ABlast::BeginOverlap);
    
    }	//CONSTRUCTOR
    
    void ABlast::BeginOverlap(class AActor* OtherActor)
    {
    
    	Destroy();
    }

Hi Oldsiren,

A few things you can check:

  1. Have you made sure the GenerateOverlapEvents is turned on in the physics options for the object? If I had to guess, I’d say this is your most likely issue.
  2. Have you tried making a simple blueprint using the actor in question(you can make it Blueprintable pretty easily) and adding a debug statement to print out when OnActorBeginOverlap to verify things when you don’t provide your own delegate?

Cheers.

Well there’s a bit more to it for what I’m doing, plus I’m intending on having it inheritable for future stuff but the only GenerateOverlapEvents bool I found that wasn’t from a component was: bGenerateOverlapEventsDuringLevelStreaming.

On the Primitive Component (which you’ll need as that is what actually contains all the collision data), there should be a bGenerateOverlapEvents, which will need to be set to true.

https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Components/UPrimitiveComponent/bGenerateOverlapEvents/index.html

That did not work.

What collision channel are you using for the object, and have you verified it is set up to overlap (and not ignore) the targets you are trying to hit?

You can use the SetCollisionChannel on the UPrimitiveComponent to change the channel (Or use SetCollisionResponseToAllChannels and pass it ECollisionResponse::ECR_Overlap to force overlap on all things - which probably isn’t what you want in the long run but could help debug things).

Alright I’m just gonna go with that then if it should work. But I’m still super confused as to why this doesn’t work even though the code seems right

Actors are effectively just containers (albeit with some special logic) for components. They don’t inherently have collision. It’s the UPrimitiveComponent that actually calls OnActorBegin/EndOverlap (you can verify this in PrimitiveComponent.cpp).

The conditions to generate an Overlap event are:

  1. Both components involved in the overlap are setup to generate overlap events.
  2. The overlap isn’t marked as ignore/block by the collision channels.

(See PrimitiveComponent.cpp:CanComponentsGenerateOverlap - Line 115)

Assuming you downloaded the engine source, you can easily put a break point in PrimitiveComponent.cpp where it calculates the overlaps and see if/why it’s failing.

Now here’s the crazy part, the collision won’t work for the primitive component either?! I even added a box component and binded it and yet it doesn’t register?!

Spawn two of these ABlast objects right next to each other so they overlap and see what you get. You can also just use a SphereComponent and call set radius with a large value to make doubly sure they are going to overlap.

That way you know both objects have generate overlap turned on, they’re next to each other, they have different owning Actors with collision enabled, and thus should be generating events (which again, you add a breakpoint in UPrimitiveComponent::UpdateOverlaps and see what is going on).

I tried having two overlap each other, nothing. I tried using very large sphere components, nothing. I didn’t download the engine source code so I can’t add breakpoints to it.

Everything should be working then. The only other thing that struck out at me is that you could move the line where you add the delegate out of the constructor (I avoid constructor logic given how UE’s serialization code works), and move it into PostLoad where you know nothing is going to stomp it.

Beyond that check the Collision Document and see if you are missing something, or download the Engine source/symbols so you can fully step through things (which is helpful even if you never plan to alter the engine).

The function signiture for, “OnActorBeginOverlap”, is:

DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams( FActorBeginOverlapSignature, AActor*, OverlappedActor, AActor*, OtherActor );

This translates into something like:

UFUNCTION( )
void OnActorOverlap(AActor* OverlappedActor, AActor* OtherActor);

OnActorBeginOverlap.AddDynamic(this, &MyActor::OnActorOverlap);

void MyActor::OnActorOverlap(AActor *OverlappedActor, AActor *OtherActor)
{
     // overlap
}

You can also use a component overlap, such as a sphere component:

UFUNCTION( )
void Overlap( UPrimitiveComponent *OverlappedComponent, 
                    AActor *OtherActor, 
                    UPrimitiveComponent *OtherComp, 
                    int32 OtherBodyIndex, 
                    bool bFromSweep, 
                    const FHitResult &SweepResult );

SphereComponent->OnComponentBeginOverlap.AddDynamic( this, &MyActor::Overlap );

void MyActor::Overlap( UPrimitiveComponent *OverlappedComponent, 
                                   AActor *OtherActor, 
                                   UPrimitiveComponent *OtherComp, 
                                   int32 OtherBodyIndex, 
                                   bool bFromSweep, 
                                   const FHitResult &SweepResult )
{

}

@Kyle Langley THANK YOU SO MUCH! I have been skewering the answer hub for 3 nights looking for your answer… it seems to me it has been answered a billion times in the last 3 years how ever every single time I tried to recreate or create new it would always not compile. the simple way you laid out your answer really made it easy for me to pick apart the function relating to the API you are awesome THANKS again… seems you can just copy past… for us not so intellectual inclined.