I don't understand what he is doing with OnComponentHit

He says, go to definition, we find: FComponentHitSignature OnComponentHit;
Without any explanation he makes a search to find the next result and we find this:

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

Without explaining at all what we are looking at, he sais that to override we need to pass the same parameters and writes this:

void OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);

ignoring this part, without any explanation again

FComponentHitSignature, UPrimitiveComponent, OnComponentHit, UPrimitiveComponent*

How am I supposed to understand what the hell is he doing and why? This is frustrating and infuriating, I am about to quit this course just because this bad teacher.

1 Like

He is saying those 3 parts are to be ignored and the rest are the types and names of the parameters

Comparing the first with the first 3 parts removed and the signature of OnHit without “void OnHit(”

// v Delegate v
UPrimitiveComponent*, HitComponent, AActor*, OtherActor, UPrimitiveComponent*, OtherComp, FVector, NormalImpulse, const FHitResult&, Hit );
// v OnHit v
UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);

Notice how they are identical apart from the commas between the type and parameter name? (You cam of course name the parameters whatever you want).

Yes, the problem is, we never saw in all the course what is something like:

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

I mean, is the first time I see DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_FiveParams in my life and the teacher doesn’t explain it at all.

With your explanation now I know I can ignore everything before the name of the event , in this cae “OnComponentHit” and take the parameters in pairs and turn that into:

void OnComponentHit {
UPrimitiveComponent*, HitComponent, 
AActor*, OtherActor, 
UPrimitiveComponent*, OtherComp, 
FVector, NormalImpulse, 
const FHitResult&, Hit 
};

and then remove the comas to get this:

void OnComponentHit {
UPrimitiveComponent* HitComponent, 
AActor* OtherActor, 
UPrimitiveComponent* OtherComp, 
FVector NormalImpulse, 
const FHitResult& Hit 
};

But this is something I shouldn’t have to ask in the forums to understand, is something that had to be explained in the course.

The C++ part of Unreal Engine help does a great job of how documentation shouldn’t be.
The line in question is a macro that, on build of the code expands to give the function definition and list of parameters you mentioned above.

You can track DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_FiveParams down in the engine code by searching for it (Runtime/CoreUObject/UObject/SparseDelegate.h line443) and it sort of helps or search for its use which shows the parameter types.:

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

Really, any help on their website should show the expanded version and explain it.

As for why they use these macros, it makes their life easier when needing to make sweeping changes to the code simply by updating the macros in one place to modify parameters.

I hope this helps clarify things.

Hello,
I guess that we are speaking about ToonTanks part of C++ unreal course. And I agree with @Morderkainer on this one. I didn’t understand that part too, I think it needs much more explanations than the teacher gives.

And I want to say that this whole part of the course (ToonTanks part) is just like that. The BullCows part is MUCH better in this regard because the teacher explained everything in this part (what, how and why) and I do know and understand what every single line of code that I’ve written for this part is needed for and what it does. But in the ToonTanks part questions arise literally almost after every teacher’s step because they lack explanations so badly and I almost finished this part but still I don’t understand about 30-40% of code that I’ve written.

I really advise you to rework this part of the course to put more explanations in it.

5 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms