# How to PlayerInputComponent-\>BindAction?

**URL:** <https://forums.unrealengine.com/t/how-to-playerinputcomponent-bindaction/644326>\
**Category:** C++\
**Tags:** UE4-20, unreal-engine, UE5-0, UE4, question, CPP\
**Created:** [September 8, 2022, 12:13pm UTC](https://forums.unrealengine.com/t/how-to-playerinputcomponent-bindaction/644326 "2022-09-08T12:13:07Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [September 8, 2022, 12:13pm UTC](https://forums.unrealengine.com/t/how-to-playerinputcomponent-bindaction/644326/1 "2022-09-08T12:13:07Z")

</div>

Hi, i want to do something like in **MyCharacter.cpp**  
`PlayerInputComponent->BindAction("DiscardWeapon", IE_Pressed, , Other , &AMyPlayerController::DiscardWeapon);`

how to access and bind the function `DiscardWeapon` form **AMyPlayerController** class?

---

<div class="post-metadata">

**Author:** ![Polite\_Muon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Polite\_Muon](https://forums.unrealengine.com/u/Polite_Muon)\
**Post date:** [September 8, 2022, 10:40pm UTC](https://forums.unrealengine.com/t/how-to-playerinputcomponent-bindaction/644326/2 "2022-09-08T22:40:17Z")

</div>

Hello Alexa.Ki, thank you for posting.

To gain the [BindAction function](https://docs.unrealengine.com/5.0/en-US/API/Runtime/Engine/Components/FInputActionBinding/) in your custom class, if not inherited, you would need to include some references as described here.

[This article](https://docs.unrealengine.com/5.0/en-US/API/Runtime/Engine/Components/UInputComponent/BindAction/) also expands on how to properly leverage the BindAction function in c++

I hope this helps.

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [September 9, 2022, 11:51am UTC](https://forums.unrealengine.com/t/how-to-playerinputcomponent-bindaction/644326/3 "2022-09-09T11:51:18Z")

</div>

Thank you sir for the answer, I know how the input bindings works, but I want to access the function from another class directly in bindings to bind.

if I use `this` instead of `other`. I should bind the function from the current class in which the bindings are declared, but I want to access the function from another class directly under bindings.

another approach i can call the foreign function from controller class in another function in the character class and bind the function using, but this needs to declare an extra function to call the foreign function.

---

<div class="post-metadata">

**Author:** ![Emaer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/emaer/32/570877_2.png) [@Emaer](https://forums.unrealengine.com/u/Emaer)\
**Post date:** [September 9, 2022, 6:09pm UTC](https://forums.unrealengine.com/t/how-to-playerinputcomponent-bindaction/644326/4 "2022-09-09T18:09:55Z")

</div>

Include header with class definition?

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [September 10, 2022, 9:22pm UTC](https://forums.unrealengine.com/t/how-to-playerinputcomponent-bindaction/644326/5 "2022-09-10T21:22:38Z")

</div>

Sir i already included and its not working, i want to directly call the function from another class in input action bindings.

---

<div class="post-metadata">

**Author:** ![Emaer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/emaer/32/570877_2.png) [@Emaer](https://forums.unrealengine.com/u/Emaer)\
**Post date:** [September 11, 2022, 7:16am UTC](https://forums.unrealengine.com/t/how-to-playerinputcomponent-bindaction/644326/6 "2022-09-11T07:16:56Z")

</div>

To call a function from another class you need two things:

- class definition (header file)
- class instance (object/pointer/reference)

Nothing less, nothing more.

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [September 11, 2022, 1:20pm UTC](https://forums.unrealengine.com/t/how-to-playerinputcomponent-bindaction/644326/7 "2022-09-11T13:20:05Z")

</div>

I can call a function from another class and this is not the quesiton, the question is how to call a function in BindAction from another class.

example: `1` this is working

```auto
MyCharacter.h
void DiscardWeapon();`

```

```auto
MyCharacter.cpp

PlayerInputComponent->BindAction("DiscardWeapon", IE_Pressed, , this, &AMyCharacter::DiscardWeapon);

```

example: `2` this needs to be achieved

```auto
MyController.h
void DiscardWeapon();`

```

```auto
MyCharacter.cpp

PlayerInputComponent->BindAction("DiscardWeapon", IE_Pressed, , /*OtehrActor*/, &AMyController::DiscardWeapon);

```

I want to achieve example 2.

---

<div class="post-metadata">

**Author:** ![Emaer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/emaer/32/570877_2.png) [@Emaer](https://forums.unrealengine.com/u/Emaer)\
**Post date:** [September 11, 2022, 2:18pm UTC](https://forums.unrealengine.com/t/how-to-playerinputcomponent-bindaction/644326/8 "2022-09-11T14:18:38Z")

</div>

This is nonsense.  
If you want invoke `APlayerController::DiscardWeapon` then you need pass `APlayerController` pointer.  
If you want invoke `ASomeOtherObject::DiscardWeapon` then you need to pass `ASomeOtherObject` pointer.

You can’t call `APlayerController` class method with _whatever-you-want_ pointer.

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [September 11, 2022, 2:37pm UTC](https://forums.unrealengine.com/t/how-to-playerinputcomponent-bindaction/644326/9 "2022-09-11T14:37:30Z")

</div>

thank you `Sir` for explaining this, you just solved my issue, Really appreciated )
