# Can I use BindAction with lambda?

**URL:** <https://forums.unrealengine.com/t/can-i-use-bindaction-with-lambda/353633>\
**Category:** Community & Industry Discussion\
**Tags:** binding, unreal-engine, UE4, question\
**Created:** [April 10, 2016, 9:51am UTC](https://forums.unrealengine.com/t/can-i-use-bindaction-with-lambda/353633 "2016-04-10T09:51:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_76eb0132](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_76eb0132](https://forums.unrealengine.com/u/anonymous_user_76eb0132)\
**Post date:** [April 10, 2016, 9:51am UTC](https://forums.unrealengine.com/t/can-i-use-bindaction-with-lambda/353633/1 "2016-04-10T09:51:40Z")

</div>

Why it’s not possible wirte this:

```
InputComponent->BindAction( "Grow", IE_Pressed, [this]()
{
    isGrowing = true;
} );

```

I’ve to write something like:

```
InputComponent->BindAction( "Grow", IE_Pressed, this, &AMyPawn::OnStartGrowing );

```

Thanks in advice!

---

<div class="post-metadata">

**Author:** ![Aaron1178](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Aaron1178](https://forums.unrealengine.com/u/Aaron1178)\
**Post date:** [April 11, 2016, 8:15am UTC](https://forums.unrealengine.com/t/can-i-use-bindaction-with-lambda/353633/2 "2016-04-11T08:15:40Z")

</div>

Too my knowledge, and I could be wrong; you are only able to use lambda on certain delegates, and only as a static function pointer. I think it would be good for BindAction, but the devs would need to sort that out, or create a class inheriting from `UInputComponent` and overriding BindAction.

---

<div class="post-metadata">

**Author:** ![Neverender](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Neverender](https://forums.unrealengine.com/u/Neverender)\
**Post date:** [June 24, 2017, 5:54am UTC](https://forums.unrealengine.com/t/can-i-use-bindaction-with-lambda/353633/3 "2017-06-24T05:54:26Z")

</div>

Not using BindAction per se, but if you look at how BindAction is implemented, you can use the same tools to do what you’re asking:

```
FInputActionBinding GrowPressedAB( "Grow", IE_Pressed );

GrowPressedAB.ActionDelegate.GetDelegateForManualSet().BindLambda( [this]()
{
	isGrowing = true;
});

InputComponent->AddActionBinding( GrowPressedAB );
```

---

<div class="post-metadata">

**Author:** ![Nightmask3](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nightmask3/32/894376_2.png) [@Nightmask3](https://forums.unrealengine.com/u/Nightmask3)\
**Post date:** [July 22, 2020, 9:49am UTC](https://forums.unrealengine.com/t/can-i-use-bindaction-with-lambda/353633/4 "2020-07-22T09:49:58Z")

</div>

Been a while since you left this but I just needed to say thank you because this helped solve my exact problem. Gratitude.

---

<div class="post-metadata">

**Author:** ![rubm123](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rubm123/32/476292_2.png) [@rubm123](https://forums.unrealengine.com/u/rubm123)\
**Post date:** [December 7, 2022, 5:21pm UTC](https://forums.unrealengine.com/t/can-i-use-bindaction-with-lambda/353633/5 "2022-12-07T17:21:21Z")

</div>

This doesn’t seem to be possible for the [Enhanced Input](https://docs.unrealengine.com/5.1/en-US/enhanced-input-in-unreal-engine/), anymore.

```cpp
FEnhancedInputActionEventDelegateBinding<void()> Binding(Action, ETriggerEvent::Triggered); // doesn't accept FName
Binding.Delegate. ??? // doesn't have `GetDelegateForManualSet`
Cast<UEnhancedInputComponent>(InputComponent)-> ??? // doesn't have a way to add `FEnhancedInputActionEventDelegateBinding`

```

---

<div class="post-metadata">

**Author:** ![rubm123](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rubm123/32/476292_2.png) [@rubm123](https://forums.unrealengine.com/u/rubm123)\
**Post date:** [January 6, 2023, 3:57pm UTC](https://forums.unrealengine.com/t/can-i-use-bindaction-with-lambda/353633/6 "2023-01-06T15:57:21Z")

</div>

i switched to templated functions now, i.e. non-type template parameters, to a similar effect.

> <https://github.com/rubenmoor/projectzero/blob/main/BindInputToTemplatedFunction.md>

---

<div class="post-metadata">

**Author:** ![Swogers](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Swogers](https://forums.unrealengine.com/u/Swogers)\
**Post date:** [March 16, 2023, 5:22pm UTC](https://forums.unrealengine.com/t/can-i-use-bindaction-with-lambda/353633/7 "2023-03-16T17:22:33Z")

</div>

this would work, but doesnt account for the InputActionValue that is passed from the InputComponent

EDIT: im dumb. this does work perfectly. to get the FInputActionValue passed, all you have to do is ensure the template function is inside the CPP file AND have it as a parameter within the function. the BindAction will automatically pass the FInputActionValue if present

---

<div class="post-metadata">

**Author:** ![keatz555](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@keatz555](https://forums.unrealengine.com/u/keatz555)\
**Post date:** [September 13, 2023, 9:03pm UTC](https://forums.unrealengine.com/t/can-i-use-bindaction-with-lambda/353633/8 "2023-09-13T21:03:43Z")

</div>

@rubm123 Thank you!
