How to use OnActorBeginOverlap c++ code?

Hi, I have a class inheriting from Character. He has by default a CapsuleComponent. And I want to define the behavior of the overlapping event inside the code.

I would appreciate a step by step instruction with possible explanation of this magnificent feet, or a reference to something similar.

Note Please assume that I have very little knowledge of what Multicast Delagate is.

In your class constructor you have to bind a function to your component, something along the lines of:

CapsuleComponent->OnComponentBeginOverlap.AddDynamic(this, &AYourClass::YourFunction);

Then either set the behaviour of the component in an inherited blueprint or before you bind it in c++. Look up the functions available and how collision channels work in ue4 to know what is going to actually fire the event. Id suggest creating another component and setting that thing’s behaviour, then attaching it to the root component all in c++. Im sure if you look around a bit you’ll find a lot of examples and tutorials. I think the C++ tutorial by epic covers this topic and shows the code.

can you help me with the signiture of “YourFunction” because I am doing it like in the tutorial and it doesn’t compile.

and maybe if you know what for is the “this” variable, and what is the difference between .AddDynamic .Add .AddUnique. All questions that dont let me sleep at night.

Im not looking at the tutorial at the moment, but the function signature im using is this:
void BeginOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult);

The this pointer is used probably to identify the instance of the character. This is so that the code uses that instance’s function. So it does this->BeginOverlap, otherwise it wont know WHICH character the event function is calling.

hhmmmm, I dont get it. We are giving the capsule the function that it needs to activate upon overlap event. What more information from the character does it need?

unless if we would want the capsule trigger an even in another character. Then it would only be possible if the object pointer is given. I guess that simply for compatability reasons they can’t change the function to “this by default” anymore because they placed it as the first argument.

You might not be calling a member function. You might be calling another system’s function or another instance. You can call anything you want. The design is flexible that way.

nvm, I guess the only way to really know is to look at the source, which I dont really intend to do.

edit this line into your answer so I could mark it as a full answer.

You probably need to make the “YourFunction” have UFUNCTION() above it. Otherwise the delegate system can’t access it.

See OnComponentBeginOverlap | Unreal Engine Documentation for an example