diff --git a/Source/EventCenterPlugin/Private/EventSourceActor.cpp b/Source/EventCenterPlugin/Private/EventSourceActor.cpp index d834dc3..e30017c 100644 --- a/Source/EventCenterPlugin/Private/EventSourceActor.cpp +++ b/Source/EventCenterPlugin/Private/EventSourceActor.cpp @@ -97,8 +97,7 @@ void AEventSourceActor::Subscribe(const FString& Channel) if (!redis->SubscribeReply.IsBound()) { UE_LOG(EventSourceLog, Log, TEXT("Subscribe(): binding event")); - //redis->SubscribeReply.AddDynamic(this, "AEventSourceActor::SubscribeCallback(FString Channel, FString Message)"); - redis->SubscribeReply.AddDynamic(this, &AEventSourceActor::SubscribeCallback); + redis->SubscribeReply.AddDynamic(this, &AEventSourceActor::InternalSubscribeCallback); } } @@ -113,9 +112,14 @@ void AEventSourceActor::Unsubscribe(const FString& Channel) redis->Unsubscribe(Channel); } -void AEventSourceActor::SubscribeCallback(FString Channel, FString Message) +void AEventSourceActor::InternalSubscribeCallback(FString Channel, FString Message) { //UE_LOG(EventSourceLog, Log, TEXT("SubscribeCallback(): %s %s"), Channel, Message); UE_LOG(EventSourceLog, Log, TEXT("SubscribeCallback(): called")); + + if (MyDelegate.IsBound()) { + MyDelegate.Broadcast(Channel, Message); + + } } diff --git a/Source/EventCenterPlugin/Private/SpawningActor.cpp b/Source/EventCenterPlugin/Private/SpawningActor.cpp index 6138fc0..8b28515 100644 --- a/Source/EventCenterPlugin/Private/SpawningActor.cpp +++ b/Source/EventCenterPlugin/Private/SpawningActor.cpp @@ -58,3 +58,10 @@ void ASpawningActor::Spawn() spawnedActor->StartDestroyTimer(10.0); } +void ASpawningActor::SpawnCallback(FString Channel, FString Message) +{ + UE_LOG(EventSourceLog, Log, TEXT("SpawnCallback()")); + + Spawn(); +} + diff --git a/Source/EventCenterPlugin/Public/EventSourceActor.h b/Source/EventCenterPlugin/Public/EventSourceActor.h index 6d5ee1d..a985f36 100644 --- a/Source/EventCenterPlugin/Public/EventSourceActor.h +++ b/Source/EventCenterPlugin/Public/EventSourceActor.h @@ -18,6 +18,8 @@ DECLARE_LOG_CATEGORY_EXTERN(EventSourceLog, Log, All); * Manages an underlying Redis pubsub subscription and coordinates dispatch to other actors. */ +DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FMySubscriberDelegate, FString, Channel, FString, Message); + // NB(bt): "Blueprintable" seems to remove the ability to add BP event nodes. UCLASS() class EVENTCENTERPLUGIN_API AEventSourceActor : public AActor @@ -61,6 +63,9 @@ public: UPROPERTY(BlueprintAssignable) FSubscribeReply SubscribeReplyy; + /** Again, what do. */ + UPROPERTY(BlueprintAssignable) + FMySubscriberDelegate MyDelegate; protected: // Called when the game starts or when spawned @@ -74,7 +79,7 @@ private: // Handle callbacks. // NB(bt): Declared 'UFUNCTION()' so reflection enables as a delegate callback. UFUNCTION() - void SubscribeCallback(FString Channel, FString Message); + void InternalSubscribeCallback(FString Channel, FString Message); public: // Called every frame diff --git a/Source/EventCenterPlugin/Public/SpawningActor.h b/Source/EventCenterPlugin/Public/SpawningActor.h index ac54348..0a7476b 100644 --- a/Source/EventCenterPlugin/Public/SpawningActor.h +++ b/Source/EventCenterPlugin/Public/SpawningActor.h @@ -24,6 +24,10 @@ public: UFUNCTION(BlueprintCallable, Category = "SpawningActor") void Spawn(); + /** Create actor with delegation callback. */ + UFUNCTION(BlueprintCallable, Category = "SpawningActor") + void SpawnCallback(FString Channel, FString Message); + /** Mesh to use */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SpawningActor", meta = (AllowPrivateAccess = "true")) class UStaticMeshComponent* BaseMesh;