How do you know which arguments to pass in Hit Events?

I was looking through the documentation for the UE OnComponentHit and I understand you throw in a callback function there as when something is hit data is sent to that function. My question is regarding how do you know what paramets will be in that callback function? for example, we have OnHit(parameter, parameter, parameter)

where are you getting these arguments? I couldn’t find it in the documentation anywhere (maybe i’m overlooking it or looking in the wrong place)

I’d like to know this as there may be times in the future i’d have to dig into the documentation myself to find answers I can’t find in a video.

Btw. Great videos and thanks.


I would realy like to know if there is a better way than the one i am currently using. I search the solution for the OnComponentHit.

Sample From VS:

This gives me the defition :

Now you can look at the Signature(In this case FComponentHitSignature):

Here is the Code:

DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_FiveParams( FComponentHitSignature, UPrimitiveComponent, OnComponentHit, UPrimitiveComponent*, HitComponent, AActor*, OtherActor, UPrimitiveComponent*, OtherComp, FVector, NormalImpulse, const FHitResult&, Hit );

From here you can Extract the needed Parameters.

It is a bit better with Rider cause the Intelisense gives better hints and it searches faster. Maybe I am to
used to Java Programming to be happy with this workflow…

1 Like

@cazgamedev I had basically the same question, since the documentation doesn’t tell much here. Seems like going to definitions inside the engine codebase is quite frequently required. Seems like devs have to get used to that.
Since the event handling seems to be a very useful system it may be worth learning all that, even it’s a little hidden.
Thanks to @benderbiber for the answer.

Came here for the same reason. A teacher shouldn’t use “magic” stuff. Don’t tell me the OnHit function needs this, this and this, without any explanation, explain me how to know OnHit function needs those arguments.

If he has to search the definitions inside engine code, show us the process, so when we face something similar, we know how to do it.

I was so happy with this new version of ToonTanks until this part, when suddenly we go back to the same problem of previous version of ToonTannks where the teacher just says loud what he writes without explaining how.

@Morderkainer Since I started the course just a week ago I wasn’t aware of the hisotry of it and just checked a few of your posts about ToonTanks. And that it was updated etc.

So basically I only did the new version. I understood everything until this lecture, too. And then I just hit a wall, I kind of expected this TBH and thought its just me lacking basic C++ knowledge about delegates and events.

I did 2-3 additional sections of TonnTanks but I’m still stuck on reading about delegates / events and Actor communication in general on the UE docs.

Is this topic picked up later in the course / explained once more?

@Tarvish don’t know, I’ve been searching and trying to learn about delegates and AddDynamic.

To answer some questions.

The function you are adding to the delegate needs the specific signature because when the event happens the delegate will be calling the functions with arguments of those specific types e.g.

Func(1, 20.f, 'h');

So in this example if the function doesn’t have int, float, char as parameters then there’s issues.

A minimal code example

Compiler Explorer

The broadcasts would be in engine code and would be called when the component hits something.
I should probably mention that this isn’t how Unreal implements this but the general idea is the same.

@sampattuzzi this is something to keep in mind for the remaster. Do you want me to create an issue on notion?

Problems with the lesson:
1- Nobody explain us what is a Delegate, how to search for em (because it is something to search in the code, not documentation), how it looks, how to understand it and how to use it.
2- Nobody explain us what is a bind, specially BindDynamic, what it does, how to use it.

The lesson is basically: we need to create a bind to OncomponentHit with AddDynamic and create an OnHit function that takes these parameters (and proceed to write em while saying em).

Imagine teaching maths to a kid and say “we need to divide 20 between 5, we write 20:5 and the answer is 4”, without teaching him how to divide or what is a division. The kid would like “why 4? where that 4 came from? how do you know it is 4 and not 2 o 10?”. So this is how I look with Delegates and BindDynamic after this lesson.

Same happens with Health Component lesson: “we are going to add a callback function, now this can be void and we can call it anything we like, and because we are binding it to a delegate, it has to have the correct input parameters appropriate for that delegate. Now for functions bound to the ontakeanydamage delegate, the input parameters list has to be like that follows…” and proceed to write em while reading em.

Same problem, how do we know those parameters with that explanation? how do we find that delegate?

I was able to find this for OnTakeAnyDamage thanks to @benderbiber post and a discord user, but not thanks to the video lesson. And still don’t really know how it works and why we skip the first 3 parameters “FTakeAnyDamageSignature, AActor, OnTakeAnyDamage”.

DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_FiveParams( FTakeAnyDamageSignature, AActor, OnTakeAnyDamage, AActor*, DamagedActor, float, Damage, const class UDamageType*, DamageType, class AController*, InstigatedBy, AActor*, DamageCauser );

All this stuff should stay inside the video lessons, not on discord and the forum, because I was lucky a discord user took his time to explain me some stuff, but the next student maybe isn’t that lucky.

All good points and I agree, however the course is being remastered soon™ so I’m not sure how Sam plans to address this (hence the tag).

Well, don’t need to. Just like you don’t need to know how the property system works in order to use it. You don’t need to know what that macro is doing beyond declaring a multi-cast delegate.

That requires knowing the inner details of that macro. This is more of a failure of the documentation than anything, you shouldn’t really need to know that that macro even exists.

For what it’s worth the macro usage

DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_FiveParams( FComponentHitSignature, UPrimitiveComponent, OnComponentHit, UPrimitiveComponent*, HitComponent, AActor*, OtherActor, UPrimitiveComponent*, OtherComp, FVector, NormalImpulse, const FHitResult&, Hit );

Expands to

class FComponentHitSignature_MCSignature : public TBaseDynamicMulticastDelegate<FWeakObjectPtr, void, UPrimitiveComponent*, AActor*, UPrimitiveComponent*, FVector, const FHitResult&> 
    FComponentHitSignature_MCSignature() { } 
    explicit FComponentHitSignature_MCSignature( const TMulticastScriptDelegate<>& InMulticastScriptDelegate ) : TBaseDynamicMulticastDelegate<FWeakObjectPtr, void, UPrimitiveComponent*, AActor*, UPrimitiveComponent*, FVector, const FHitResult&>( InMulticastScriptDelegate ) { } 
    void Broadcast(UPrimitiveComponent* InParam1, AActor* InParam2, UPrimitiveComponent* InParam3, FVector InParam4, const FHitResult& InParam5 ) const 
        FComponentHitSignature_DelegateWrapper(*this, InParam1, InParam2, InParam3, InParam4, InParam5 ); 

struct FComponentHitSignatureInfoGetter
    static const char* GetDelegateName() { return "OnComponentHit"; } 
    template<typename T> static size_t GetDelegateOffset() 
        return offsetof(T, OnComponentHit); 

struct FComponentHitSignature : public TSparseDynamicDelegate<FComponentHitSignature_MCSignature, UPrimitiveComponent, FComponentHitSignatureInfoGetter> 


The first argument names the class/structs.
The second argument is part of inheriting from TSparseDynamicDelegate at the end. Looking at that class for the first time, the argument is for the owning class

/** Sparse version of TBaseDynamicDelegate */
template <typename MulticastDelegate, typename OwningClass, typename DelegateInfoClass>
struct TSparseDynamicDelegate : public FSparseDelegate

No clue about the inner workings of that class. Though I don’t have to.
The third argument names the delegate name as seen in FComponentHitSignatureInfoGetter.

The rest are the parameter types and the parameter names although the names are seemingly stripped out by the macro so are only there for readers.