TakeDamage() in ToonTanks needs better explanation

Consider this constructive criticism - the Toon Tank lectures are step-by-step directions, but less of a learning experience compared to the earlier projects.

The previous lectures explained the craft very well.
For Toon Tanks the lecturer clearly knows what he is doing, but understanding the WHY in what we do is the key that is missing.

((I know the topic is advanced, and I probably couldn’t explain it any better myself.))

I’m going through 150. Adding Health Functionality.
The lecturer starts talking about binding an OnTakeAnyDamage() function, so I look it up.

On the UE4 Docs I found an AActor::TakeDamage function, that has similar input paramaters to the TakeDamage() function we created last lecture.

So what happens when we create a function that has the same name as an existing UE4 function called TakeDamage() ?

Also, is there any better reference for OnTakeAnyDamage() as the lecturer asks us to assemble that function as a binding function to the Owner returned by GetOwner(), but the UE4 docs seem to be very lacking.

Yes, the UE4 docs are sometimes lacking - the lecturer mentioned this himself in lecture number 147.
So he says to use Intellisense lookup instead.

we override TakeDamage() virtual function. This means when TakeDamage() function is called in the parent class it’s going to call your version of it instead.

I thought we needed to declare virtual void FunctionName() override

Like that ^^^

The BeginPlay() is done that way.

So we can override a parent function just by declaring a function of the same name? That doesn’t sound right.

you can actually do it that way. Only the parent function needs to be virtual. override is just for security, because it does not allow you to compile if you are not actually overriding anything

but it’s recommended to put override because it makes your code easier to read. Also you avoid mistakes like misspelling with that.

Ok I looked up TakeDamage() again.

The first like in the Syntax says:
virtual float TakeDamage

Hmm, so in that new TakeDamage() function we could add override to the end of the declaration?
That would be the better practice?

yes it would be

1 Like

thanks.

I guess extra study is needed to progress with these chapters.

at least this section teaches you how to gather information yourself. Gamedev.tv is actually planning to update this section

Gathering information and plentiful note-taking. Aye.

An update? I wonder what they have in store.

Oh well, back to it for now…

EDIT:
If anyone can help me locate parameter listings for OnTakeAnyDamage() then thankyou so much.

if you have no more questions, I would recommend putting this thread resolved

A couple things, @Mikapo has probably forgotten what was done in Toon Tanks.

What is done in Toon Tanks was that a new function was created in the health component called TakeDamage, this is a brand new non-virtual function. It will be called when the owning actor’s OnTakeAnyDamage event happens; that is set up through using AddDynamic on that.

Unfortunately those aren’t in the documentation AFAIK, you will have to locate that through the source code. If you go to definition for OnTakeAnyDamage you should come to

/** Called when the actor is damaged in any way. */
UPROPERTY(BlueprintAssignable, Category="Game|Damage")
FTakeAnyDamageSignature OnTakeAnyDamage;

If you then go to definition for FTakeAnyDamageSignature you should come to this beauty

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

The first three arguments can be ignored, that’s just naming the delegate type, what type it’s on, and the name of it. The rest of the arguments are the parameter list with the types and parameter names separated by commas.

2 Likes

Oh wow, thankyou for all of that.

I will definitely write this down.

I’m in the process of reviewing all the Dynamic Delegation parts.
Thanks for your added knowledge.

Privacy & Terms