# Pass a variable between two actors

**URL:** <https://forums.unrealengine.com/t/pass-a-variable-between-two-actors/491226>\
**Category:** Editor Scripting\
**Tags:** overlapping, Variable, bool, unreal-engine, question\
**Created:** [November 23, 2021, 12:52pm UTC](https://forums.unrealengine.com/t/pass-a-variable-between-two-actors/491226 "2021-11-23T12:52:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aliAghel](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@aliAghel](https://forums.unrealengine.com/u/aliAghel)\
**Post date:** [November 23, 2021, 12:52pm UTC](https://forums.unrealengine.com/t/pass-a-variable-between-two-actors/491226/1 "2021-11-23T12:52:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![CtnDev](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ctndev/32/1133321_2.png) [@CtnDev](https://forums.unrealengine.com/u/CtnDev)\
**Post date:** [November 23, 2021, 1:50pm UTC](https://forums.unrealengine.com/t/pass-a-variable-between-two-actors/491226/2 "2021-11-23T13:50:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![aliAghel](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@aliAghel](https://forums.unrealengine.com/u/aliAghel)\
**Post date:** [November 23, 2021, 5:29pm UTC](https://forums.unrealengine.com/t/pass-a-variable-between-two-actors/491226/3 "2021-11-23T17:29:01Z")

</div>

Thank you

---

<div class="post-metadata">

**Author:** ![CtnDev](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ctndev/32/1133321_2.png) [@CtnDev](https://forums.unrealengine.com/u/CtnDev)\
**Post date:** [November 23, 2021, 6:34pm UTC](https://forums.unrealengine.com/t/pass-a-variable-between-two-actors/491226/4 "2021-11-23T18:34:38Z")

</div>

Please mark as answer 🙂

---

<div class="post-metadata">

**Author:** ![aliAghel](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@aliAghel](https://forums.unrealengine.com/u/aliAghel)\
**Post date:** [November 23, 2021, 7:22pm UTC](https://forums.unrealengine.com/t/pass-a-variable-between-two-actors/491226/5 "2021-11-23T19:22:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![CtnDev](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ctndev/32/1133321_2.png) [@CtnDev](https://forums.unrealengine.com/u/CtnDev)\
**Post date:** [November 23, 2021, 7:50pm UTC](https://forums.unrealengine.com/t/pass-a-variable-between-two-actors/491226/6 "2021-11-23T19:50:39Z")

</div>

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