I’m trying to make events that get triggered from c++ code, execute some c++ code, and then execute an event in blueprint. Should function just as AActor::BeginPlay() does, and I don’t want to have to “bind” things to the event in blueprint.
But, the blueprint event isn’t the same delegate as my UProperty, and isn’t getting called when my delegate is dispatched.
My code so far:
Weapon.h:
#pragma once
#include "GameFramework/Actor.h"
#include "Weapon.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FBPDelegate);
UCLASS()
class TRAVELER_API AWeapon : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AWeapon();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat)
float Damage;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat)
bool StopOnClank;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Combat)
bool IsAttacking;
UPROPERTY(EditAnywhere,BlueprintAssignable, Category = "Combat")
FBPDelegate Start;
UFUNCTION()
virtual void Start_Implementation();
UPROPERTY(EditAnywhere,BlueprintAssignable, Category = "Combat")
FBPDelegate End;
UFUNCTION()
virtual void End_Implementation();
UPROPERTY(EditAnywhere,BlueprintAssignable, Category = "Combat")
FBPDelegate Clank;
UFUNCTION()
virtual void Clank_Implementation();
};
Weapon.cpp:
#include "Weapon.h"
AWeapon::AWeapon()
{
PrimaryActorTick.bCanEverTick = true;
}
void AWeapon::BeginPlay()
{
Super::BeginPlay();
Start.AddDynamic(this, &AWeapon::Start_Implementation);
End.AddDynamic(this, &AWeapon::End_Implementation);
Clank.AddDynamic(this, &AWeapon::Clank_Implementation);
// for testing only
End.Broadcast();
}
void AWeapon::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}
void AWeapon::Start_Implementation()
{
IsAttacking = true;
}
void AWeapon::End_Implementation()
{
IsAttacking = false;
}
void AWeapon::Clank_Implementation()
{
End.Broadcast();
}
Blueprint:
As you can see, the events do appear as “event dispatchers” in BP, and I can drag them in and select “Event”. But, unlike BeginPlay(), I need to bind these events before they can be called, and I can’t call them from C++.