# How to call BindAction on an object of another class instead of \`this\`

**URL:** <https://forums.unrealengine.com/t/how-to-call-bindaction-on-an-object-of-another-class-instead-of-this/566956>\
**Category:** C++\
**Tags:** unreal-engine, CPP\
**Created:** [May 26, 2022, 11:15am UTC](https://forums.unrealengine.com/t/how-to-call-bindaction-on-an-object-of-another-class-instead-of-this/566956 "2022-05-26T11:15:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Krrishkutta](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Krrishkutta](https://forums.unrealengine.com/u/Krrishkutta)\
**Post date:** [May 26, 2022, 11:15am UTC](https://forums.unrealengine.com/t/how-to-call-bindaction-on-an-object-of-another-class-instead-of-this/566956/1 "2022-05-26T11:15:52Z")

</div>

I have made a function in the `Pistol` class (An `APawn`) named `APistol::Shoot()`

```auto
void APistol::Shoot()
{ /*Shoot*/ }

```

And in the `SetupPlayerInputComponent` function, I have done this:

```auto
Super::SetupPlayerInputComponent(PlayerInputComponent);

	if (InputComponent)
	{
		InputComponent->BindAction("Shoot", IE_Pressed, /*here*/, &APistol::Shoot);
	}

```

I want to call this function in such a way that the player pawn (the pawn who is holding this pistol) gives the input, and then the pistol starts shooting…  
Probably I need to replace `/*here*/` with a reference to the player pawn. But it doesn’t seem to work. There is another way, I can somehow do all this work in the player pawn’s class itself. But that would end up making the code messy. Sorry if it is common knowledge in c++ 😅,and any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![Tuerer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tuerer/32/1008648_2.png) [@Tuerer](https://forums.unrealengine.com/u/Tuerer)\
**Post date:** [May 26, 2022, 11:46am UTC](https://forums.unrealengine.com/t/how-to-call-bindaction-on-an-object-of-another-class-instead-of-this/566956/2 "2022-05-26T11:46:19Z")

</div>

The issue here is that `&APistol::Shoot` would be a call to the static class, not to the instance of the pistol. It wouldn’t work anyway.

I’d say create a function in the player class, which will call the pistol function.  
.h:

```auto
UFUNCTION()
void ShootPressed();

```

.cpp:

```auto
InputComponent->BindAction("Shoot", IE_Pressed, this, &ThisClass::ShootPressed);
...
void ShootPressed()
{
    Pistol->Shoot();
}

```

---

<div class="post-metadata">

**Author:** ![Cody325M](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/cody325m/32/911474_2.png) [@Cody325M](https://forums.unrealengine.com/u/Cody325M)\
**Post date:** [March 11, 2024, 2:08am UTC](https://forums.unrealengine.com/t/how-to-call-bindaction-on-an-object-of-another-class-instead-of-this/566956/3 "2024-03-11T02:08:35Z")

</div>

I tried google/gpt the same question but found no answer. Just found this out from Nicholas Quinn’s comment in the Tom Looman Course.

```cpp
// I think yours would look like this
InputComponent->BindAction("Shoot", IE_Pressed, this->Pistol.Get(), &APistol::Shoot);
// assuming Pistol is spawned or created in your Character.

// For reference this is how mine looks
EnhancedInputComp->BindAction(Input_Interact, ETriggerEvent::Triggered, this->InteractionComp.Get(), &USInteractionComp::PrimaryInteract);

```

It worked in PIE. I’m using Enhanced Input and TObjectPtr for the InteractionComp, but guys from the course said it works with the old Input Component and with raw pointers.

Sidenote, make sure APistol::Shoot() is not const.
