OnComponentBeginOverlap not firing

For some reason, I can not get the binded function to fire.
Here is the relevent code

Header File



// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "PPlayerPlane.generated.h"
UCLASS()
class MYPROJECT_API APlayerPlane : public APawn
{
    GENERATED_BODY()
public:
    // Sets default values for this pawn's properties
    APlayerPlane();
    UPROPERTY(EditAnywhere, Category = "Components")
    class UStaticMeshComponent* PlayerPlaneModel;
protected:
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;
public: 
    // Called every frame
    virtual void Tick(float DeltaTime) override;
    UFUNCTION()
    void OnOverlap( 
        UPrimitiveComponent* OverlappedComp, 
        AActor* OtherActor, 
        UPrimitiveComponent* OtherComp, 
        int32 OtherBodyIndex,
        bool bFromSweep, 
        const FHitResult& SweepResult 
    );
};


and the cpp file



APlayerPlane::APlayerPlane()
{
    // Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    PrimaryActorTick.bCanEverTick = true;

    PlayerPlaneModel = CreateDefaultSubobject<UStaticMeshComponent>("Base Plane Model");
    SetRootComponent( PlayerPlaneModel ); 
}
// Called when the game starts or when spawned
void APlayerPlane::BeginPlay()
{
    Super::BeginPlay();
    if ( !IsPendingKill() )
    {
        DirtyUtility :: Log( "About to bind function" );
        PlayerPlaneModel -> OnComponentBeginOverlap.AddDynamic( this, &APlayerPlane :: OnOverlap );
    }
}
void APlayerPlane :: OnOverlap (
    UPrimitiveComponent* OverlappedComp, 
    AActor* OtherActor, 
    UPrimitiveComponent* OtherComp, 
    int32 OtherBodyIndex, 
    bool bFromSweep, 
    const FHitResult& SweepResult )
{
    DirtyUtility :: Log( "This has overlaped" );
}


Note that DirtyUtility :: Log is my own logging function.

I have made sure that all actors have generate overlapping events enabled
I have made sure that the function is marked as a UFUNCTION
I have made sure that the function is binded in begin play instead of the constructer.
I also make sure the object is marked for kill

When I run the game after compiling, the log does complain that function may not be a UFUNCTION or that the object is pending kill

And when the test cube I have setup for the actor overlaps with another object, nothing happens

I never used OnOverlap, checking the API, i’m not sure you could use it like you did, as it’s marked as UPROPERTY…
Try using OnOverlapBegin, and OnOverlapEnd

You need to setup your CollisionProfile otherwise it will not work.

I’m not using the OnOverlapBegin of the actor. I’m trying to bind a function to the model’s overlap begin event.

I have, I have tested the same actors with blueprints the OnComponentOverlapBegin fires, but the c++ version doesn’t

I changed the name of the function from OnOverlap to MyOverlap, to avoid a naming confusion with the actor. Still no luck.

All I’m trying to do is bind a function to the components on overlap event

Also I keep getting this

LogOutputDevice: Error: Ensure condition failed: this->IsBound() [File:E:\Programs\Unreal\UE_4.23\Engine\Source\Runtime\Core\Public\Delegates/DelegateSignatureImpl.inl] [Line: 1136]
LogOutputDevice: Error: Unable to bind delegate to ’ MyOverlap’ (function might not be marked as a UFUNCTION or object may be pending kill)

Bumb. This is what I’m trying to implement

as seen in this tutorialhttps://youtube.com/watch?v=84B22sP2L1M
The function is a member of UPrimitiveComponent, and this on all collider components, including StaticMesh.

Ultimately my goal is to setup a component to act as a interface for game logic, a “Hitable” component, which will respond with a “hittee” component collides with it. But in order for this to work, I need to bind a function to the OnComponentOverlapEvent of the other uprimitivecomponents of the actor. However, what I have found is the event itself seems to broken and wont fire, no matter what I try, despite the blueprint version of OnComponentOverlapEvent firing correctly. I don’t what I’m missing. I have made sure it check it the actor is pending kill. I have made sure that generate overlap events are turned on for both objects.

I;ve followed the tutorial above exactly.

Does anyone know what I need to do. Because all the documentation hasn’t provided an answer.

Your signature is fine, try:

FScriptDelegate CollisionBeginOverlap;
CollisionBeginOverlap.BindUFunction(this, TEXT(“OnEnterCollision”));
MyMesh->OnComponentBeginOverlap.Add(CollisionBeginOverlap);

1 Like