Pass a variable between two actors

Hi I’m a bigginer and I have question .
I have an actor , it’s some kind of bomb and it’s has a virtual function
named OnComponentBeginOverlap that I bind it with a delegate to the root of actor wich is a sphere
Some thing like :
MainSphere->OnComponentBeginOverlap.AddDynamic()

Now that’s my question I want to pass a boolean to a AnimInstance or another actor . when player overlap with current actor , I don’t have a problem with overlaping I test it , my problem is passing the bool from this class to another class
I tried defrent ways but unfortunately it’s still not working

I will be very happy if you answer my question, I know it’s shall be very easy for you

OnOverlap delegate already keeps other actor in function variables.

For that purpose you should do.

MainSphere->OnComponentBeginOverlap.AddDynamic(this, &AClassName::FunctionName);

Here is the definition of ComponentOverlap in PrimitiveComponent.h

DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_SixParams( FComponentBeginOverlapSignature, UPrimitiveComponent, OnComponentBeginOverlap, UPrimitiveComponent*, OverlappedComponent, AActor*, OtherActor, UPrimitiveComponent*, OtherComp, int32, OtherBodyIndex, bool, bFromSweep, const FHitResult &,SweepResult);

Based on above signature macro your function (imagining its Actor) you should have function like this :

void AClassName::FunctionName(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult)
{
 if (OtherActor != nullptr)
 {
     AActor myActor = Cast<AYourPlayerClass>(OtherActor);
     if (myActor)
         myActor->DoSomething()
 }
}

At here other actor is the actor actually overlapping with this actor. So you will cast it to your main character.

If you have further questions dont hesitate to ask me.

Please mark as answer :slight_smile:

Thank you

I test it , that was true
Thank you , I am glad we have good guy like you in commniute
But some thing I want to add ,
you forgot a '’ Singh in line 5 you want to create a variable
and for other guys who will see this you can use this line of code to have direct connection to the character UAnimInstane
UCharacterAnimInstance
AnimInstance = Cast(myactor()->GetMesh()->GetAnimInstance());

UCharacterAnimInstance is your custom UAnimIntance
myactor is referenced to the answer comment

thank you such valuable comments. I’m always here to help people as much as I can.