# Dynamically change functions

**URL:** <https://forums.unrealengine.com/t/dynamically-change-functions/1252481>\
**Category:** C++\
**Tags:** Input, unreal-engine, CPP, question\
**Created:** [August 6, 2023, 12:35pm UTC](https://forums.unrealengine.com/t/dynamically-change-functions/1252481 "2023-08-06T12:35:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fus\_Ro\_Duh](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Fus\_Ro\_Duh](https://forums.unrealengine.com/u/Fus_Ro_Duh)\
**Post date:** [August 6, 2023, 12:35pm UTC](https://forums.unrealengine.com/t/dynamically-change-functions/1252481/1 "2023-08-06T12:35:43Z")

</div>

Good Day!

I have an issue with Enhanced Input system.  
I have two types of wepons: a ranged and a melee type. Each type consumes same input (Right or Left mouse button) and triggers same base class function but each type consumes different InputEvent:

```auto
// For Range Weapon
  void ABaseRangeWeapon::LeftClickAction(EInputEvent Event)
  {
	switch (Event)
	{
	    case EInputEvent::IE_Pressed:
			Load();
			break;
		case EInputEvent::IE_Released:
			Release();
			break;
	}
}

// For Melee Weapon:
void ABaseRangeWeapon::LeftClickAction(EInputEvent Event)
{
    Attack();
}

```

Is it possible to bind and remove action bindings dynamically based on the current type of weapon?  
I want to change my weapon and code removes previous weapon type functions and bind the ones of the current one

---

<div class="post-metadata">

**Author:** ![Hexavx](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Hexavx](https://forums.unrealengine.com/u/Hexavx)\
**Post date:** [August 7, 2023, 5:20am UTC](https://forums.unrealengine.com/t/dynamically-change-functions/1252481/2 "2023-08-07T05:20:52Z")

</div>

There is another approach to do this.

```auto
void AMyPlayerCharacter::LeftClickPressed()
{
    EquippedWeapon->ActionPressed();
}
void AMyPlayerCharacter::LeftClickReleased()
{
    EquippedWeapon->ActionReleased();
}

ARangedWeapon::ActionPressed()
{
    Load();
}
ARangedWeapon::ActionReleased()
{
    Fire();
}

AMeleeWeapon::ActionPressed()
{
    Attack();
}
AMeleeWeapon::ActionReleased()
{
    // Do nothing
}

```

Just by calling the function of the weapon, the code is cleaner and no need to worry the event binding.
