What with Overlap component Event

So, I trying make a simple bullet Reflector in code, nothing special.
I use this code


 	// 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;

	BoxComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("ReflectorCollision"));
	BoxComponent->BodyInstance.bUseCCD = true;
	RootComponent = BoxComponent;

	BoxComponent->OnComponentBeginOverlap.AddDynamic(this, &AReflector::OnComponentBeginOverlap);

	BoxComponent->bGenerateOverlapEvents = true;
	Arrow = CreateDefaultSubobject<UArrowComponent>(TEXT("ArrowComponent"));




void AReflector::OnComponentBeginOverlap(UPrimitiveComponent * OverlappedComponent, AActor * OtherActor, UPrimitiveComponent * OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
        	GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Yellow, TEXT("Something!"));
        	AProjectail* TestProj = Cast<AProjectail>(OtherActor);
        	if (TestProj)
        		GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Green, TEXT("Some proj!"));
        		FVector Velocity = TestProj->ProjectileMovement->Velocity;
        		Velocity *= (-1);
        		TestProj->ProjectileMovement->Velocity = FRotator(0, (Arrow->GetComponentRotation().Yaw * 2 - Velocity.Rotation().Yaw), 0).Vector()* Velocity.Size();

And, as you allready guess, It doesn’t working. It does not fire function, not only from class Projectail, but from anything (Characters, simple actors, anything)
So, any ideas why this … thing not working?

I’m not overly sure if it could solve the problem, but could you try to remove this line

BoxComponent->OnComponentBeginOverlap.AddDynamic(this, &AReflector::OnComponentBeginOverlap);

and write it in the way I show you (note that the given function must have UFUNCTION macro then):

TScriptDelegate<FWeakObjectPtr> delegateFunction;
delegateFunction.BindUFunction(this, FName("OnComponentBeginOverlap"));

The other option would be to rename the given function AReflector::OnComponentBeginOverlap as it has the same name as the delegate you bind the function to. The second suggestion probably solves the problem. I’ve encountered the same problem over and over again.

Let me know if my answer had any use :slight_smile:

With regards

Rewrite, or rename the function wasn’t the solution. The true answer was what I forgot about UFUNCTION macro (always something I forget…). Thank you for remind me about that, it was helpful :slight_smile:

Glad I could help :slight_smile: