I have a weapon component, and in order to make it so I can easily switch it out with other weapon component without having to have the player directly equip items, I am trying to have the component drive all the major attack functionality.
To make sure I can basically equip the weapon to anything based on a particular class, meaning both AI and player (i.e. AI when called through behaviour tree or something, player when called through input), I have setup a number of delegates in a base character class (from which I have extended both enemy and the player character), and then try to bind these within the weapon component.
However, I am not getting any reaction. While the IsBound() returns true, the function within the component is not being called. Here is the functionality in question:
Base Character .h
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FStartAttackSignature);
UPROPERTY(BlueprintAssignable, Category = "Attack")
FStartAttackSignature OnStartAttack;
Base character .cpp
void ABaseCharacter:StartAttack()
{
if(OnStartAttack.IsBound())
{
OnStartAttack.Broadcast();
}
}
Weapon component .h
virtual void BeginPlay() override;
void OnStartAttack();
Weapon component .cpp
void UWeaponComponent::BeginPlay()
{
WeaponOwner = Cast<ABaseCharacter>(GetOwner());
if (WeaponOwner)
{
WeaponOwner->OnStartAttack.AddDynamic(this, &UWeaponComponent::OnStartAttack);
}
Super::BeginPlay();
}
void UWeaponComponent::OnStartAttack()
{
}