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.
@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?
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.
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.