How to implement/add Component's Event inside of owning Actor?

Hello,
My question might be a little bit missleading so I’ll try to describe what I’m exacly looking for.

I’ve created an UGrabbingComponent (USceneComponent) in which I call an event:

UFUNCTION(BlueprintImplementableEvent)
void OnGrab(APropBase* GrabbedProp);

and I want to implement this ‘OnGrab’ event inside of Actor Blueprint that owns this component to trigger some logic there.

If I create new component that inherets from GrabbingComponent I can easly implement ‘OnGrab’ inside of it:
image

But this is not possible inside of owning Actor in which I can add only these few events:

So my question is:
How shall I modify ‘OnGrab’ to make it appear inside of owning Actor? just like OnComponentActivated/Deactivated events
Can I somehow achieve it with DECLARE_EVENT, DECLARE_DELEGATE macros ?

You should be able to just call it from the reference. I attached an image.

If you searching the already existing available event ‘OnComponentActivated’ from the UE source then you can find something like multicast delegate blahblah~.
I can’t answer your question but how about start from there?

1 Like

@Polysiens
I think you’ve missunderstood my question or I don’t understand your answear :v
I don’t want to “call” this event from Owning Actor. I just want to “add” it to Owning Actor (and call it from the Component itself).

@LikeThatAng
I belive this might be exacly what I need.
In ActorComponent.h I was able to find:

/* Lines 100-101 */
DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_TwoParams(FActorComponentActivatedSignature, UActorComponent, OnComponentActivated, UActorComponent*, Component, bool, bReset);
DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_OneParam(FActorComponentDeactivateSignature, UActorComponent, OnComponentDeactivated, UActorComponent*, Component);

/* Lines 386-392 */
/** Called when the component has been activated, with parameter indicating if it was from a reset */
	UPROPERTY(BlueprintAssignable, Category = "Components|Activation")
	FActorComponentActivatedSignature OnComponentActivated;

	/** Called when the component has been deactivated */
	UPROPERTY(BlueprintAssignable, Category = "Components|Activation")
	FActorComponentDeactivateSignature OnComponentDeactivated;

I’ll check it later and give the proper response.
Thanks!

1 Like

Well well well, the DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE was the way to go.
It’s probably an overkill in this case but it works xD There might be more optimal way to implement it though.

Few notes worth mentioning
  • This behaves just like a regular delegate when trying to access it inside of inhereted component (in Blueprints). Not an issue in my case.
  • DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE and UPROPERTY (used as Delegate) have to be declared as public.
  • Wasn’t able to find the exact documentation about “Dynamic Multicast Sparse Delegate”. Delegates page doesn’t really mention about it (or I was too impatient to find it). I’ve just followed the code from ActorComponent.h
Posting snipped of my code as example

.h

class UGrabbingComponent;
DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_OneParam(FOnGrab, UGrabbingComponent, OnGrab, AProp*, GrabbedProp);

UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent), Blueprintable )
class MyProject_API UGrabbingComponent : public USceneComponent
{
	GENERATED_BODY()

public:
	
	UPROPERTY(BlueprintAssignable)
	FOnGrab OnGrab;
};

.cpp

OnGrab.Broadcast(/* AProp* */ GrabbedProp);

Then from Owning Actor it can be added here:

3 Likes