Beginoverlap is not working

CLog::Print(actor->GetActorEnableCollision());
UCapsuleComponent* capsule = CHelpers::GetComponent(actor);
capsule->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
capsule->SetCollisionObjectType(ECollisionChannel::ECC_EngineTraceChannel1);


but beginoverlap not warking…TT
what’s the problem??

I struggled with this problem for 4 hours…
Please help…

Hello @kya7771 !

It looks like the collisions are well set on the editor (make sure that both actors are set to overlap with the other’s actor collision channel). But you are missing a few things in the cpp class.

The header of the actor has to look something like this

#pragma once
#include "Components/BoxComponent.h"
#include "Components/CapsuleComponent.h"
#include "Components/SphereComponent.h"
#include "MyExample.generated.h"

UCLASS()
class AMyExample : public AActor
{
	GENERATED_BODY()
	
public:
	AMyExample();

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
	UBoxComponent* BoxCollision;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
	UCapsuleComponent* CapsuleCollision;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
	USphereComponent* SphereCollision;

	virtual void BeginPlay() override;

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

For this example, I declared 3 different collision components (not a good idea to implement more than 1 per actor). BoxCollision, CapsuleCollision and SphereCollision. Then I override the BeginPlay() as it will be there that we are going to subscribe our function to that event/delegate of the component OnBeginOverlap. And finally I declared a function that will trigger everytime my components overlap with something OnAnyCollisionBeginOverlap (NOTE: The parameters of that function are extremely important if you don’t declare them. It will not work, for context I use the parameters of the delegate on its signature)

The signature that I’m talking about

/** Delegate for notification of start of overlap with a specific component */
DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_SixParams( FComponentBeginOverlapSignature, UPrimitiveComponent, OnComponentBeginOverlap, UPrimitiveComponent*, OverlappedComponent, AActor*, OtherActor, UPrimitiveComponent*, OtherComp, int32, OtherBodyIndex, bool, bFromSweep, const FHitResult &, SweepResult);

Then for the cpp file, we have this:

#include "MyExample.h"


AMyExample::AMyExample()
{
	// creating the collisions components
	BoxCollision = CreateDefaultSubobject<UBoxComponent>(TEXT("BoxCollisionComponent"));
	SphereCollision = CreateDefaultSubobject<USphereComponent>(TEXT("SphereCollisionComponent"));
	CapsuleCollision = CreateDefaultSubobject<UCapsuleComponent>(TEXT("CapsuleCollisionComponent"));

	// placing the collisions on the world
	BoxCollision->SetupAttachment(RootComponent);
	SphereCollision->SetupAttachment(RootComponent);
	CapsuleCollision->SetupAttachment(RootComponent);
}

void AMyExample::BeginPlay()
{
	Super::BeginPlay();

	// subscribes my function "OnAnyCollisionBeginOverlap" to the delegate of the components "OnComponentBeginOverlap"
	// this means that whenever those components begin an overlap with another component, this actor is gonna trigger the function
	// "OnAnyCollisionBeginOverlap"
	BoxCollision->OnComponentBeginOverlap.AddDynamic(this, &AMyExample::OnAnyCollisionBeginOverlap);
	SphereCollision->OnComponentBeginOverlap.AddDynamic(this, &AMyExample::OnAnyCollisionBeginOverlap);
	CapsuleCollision->OnComponentBeginOverlap.AddDynamic(this, &AMyExample::OnAnyCollisionBeginOverlap);
}

void AMyExample::OnAnyCollisionBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
	UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
	// What to do on a overlap
	// Your code goes here
}

And with that, it should work as intended. Hope this solves your question!

Can’t I have this for the overlap event?

Thought you were implementing it on C++ (because of the post tag), but nevermind. What your blueprint is saying is : " Whenever something overlaps with this actor, then its going to stop the movement immediately of the Projectile Movement variable you have, then call function Detroy after 3 seconds. ". It’s a little weird to be honest, I think what you want to do is Cast as a Projectile the Other Actor of the OnComponentBeginOverlap node, then for that projectile, stop movement immediately and then use a Delay Node for 3 seconds and finally a Destroy (whatever you wanted to destroy) node.

It was solved by setting the collision to overlap world dynamic!