Hi! Does someone know how to notify actor overlapping in c++? I suspected that there is some event. I found OnComponentBeginOverlap() but I have no idea how to use it. Can someone help me with this?
This may help you
If you want to use OnComponentBeginOverlap(), you will need to use Delegates.
Step1: Register your PrimitiveComponent to receive the delegate broadcast
YourComponentPrimitive->OnComponentBeginOverlap.AddUniqueDynamic(this, &YourComponent::CapsuleTouched);
Step2: Create the function to handle the delegate call.
void YourComponent::CapsuleTouched( AActor* Other, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult )
Now you have any information you need about the actors overlapping each other.
Step 3: Make sure to clean up your delegates when the actor is removed
if (YourComponentPrimitive->OnComponentBeginOverlap.IsBound())
{
YourComponentPrimitive->OnComponentBeginOverlap.RemoveDynamic(this, &YourComponentPrimitive::CapsuleTouched);
}
Hope that helps =)
I’m still having some problems…
I have this in my header file
UFUNCTION()
void CapsuleTouched();
and this in my constructor .cpp
CollisionSphere->OnComponentBeginOverlap.AddUniqueDynamic(this, &AMyActorClass::CapsuleTouched);
and this below
void AMyActorClass::CapsuleTouched(AActor* Other, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
but compiler is giving me some crazy errors
You need to add the arguments to be passed into the function
UFUNCTION()
void CapsuleTouched(AActor* Other, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
Hopefully that is it =)
Yes. That was it. Thank you very much