What's the condition for broadcasting?

Ah, still me trying to get things straight. So,

  1. If the on component hit wants to broadcast, a hit event needs to happen. And this event can happen during game play when the projectile hits something. The hit event is set in the default BluePrint where collision is located. Is this correct?

2.If the on take any damage wants to broadcast and call the function which can deduct health, it needs to be triggered by UGameStatics::ApplyDamage, which is set in code and will not generate by itself. Is this correct?

I’m not sure what you mean by this. Would you mind elaborating/rephrasing?

This is incorrect because UGameStatics::ApplyDamage is just a wrapper for convivence for creating a base damage event and then calling TakeDamage on the actor.

Spoiler for the next section in which a specific damage event is used so does it “manually”
Source/SimpleShooter/Gun.cpp · master · GameDev.tv / Unreal Course / 05 Simple Shooter · GitLab

Sorry, please allow me to paraphrase. So what generates the hit event? Is it the settings in default blueprint?


You know the collision presets stuff.

Or the code on component hit?

So do you mean that there are many other things to call TakeDamage but the basic condition to call it is to have a damage event?

The thing having collision and well… hitting something (blocking). Note this only applies if it’s not simulating physics. If it’s simulating physics then you need to enable “Simulation Generates Hit Events”. Presumably because it requires more computational effect.

Well the condition being “called TakeDamage”. If you look at the source code there’s

if (DamageEvent.IsOfType(FPointDamageEvent::ClassID))
{
    // ...
}
else if (DamageEvent.IsOfType(FRadialDamageEvent::ClassID))
{
    // ...
}

// generic damage notifications sent for any damage
// note we will broadcast these for negative damage as well
if (ActualDamage != 0.f)
{
	ReceiveAnyDamage(ActualDamage, DamageTypeCDO, EventInstigator, DamageCauser);
	OnTakeAnyDamage.Broadcast(this, ActualDamage, DamageTypeCDO, EventInstigator, DamageCauser);
	if (EventInstigator != nullptr)
	{
		EventInstigator->InstigatedAnyDamage(ActualDamage, DamageTypeCDO, this, DamageCauser);
	}
}

Thanks. After going over the videos many times and drawing different graphs and reading your reply, I think I’ve got it.

I still have one more question though:

How does the float Damage that I declared in Projectiles get passed to Health component?

Does this mean when UGameStatic::ApplyDamage triggers OnTakeAnyDamage, it can also pass value cross classes?

ApplyDamage calls TakeDamage and you can see from that code above, that damage is passed into the Broadcast

OnTakeAnyDamage.Broadcast(this, ActualDamage, DamageTypeCDO, EventInstigator, DamageCauser);

which will be calling your function in the HealthComponent as you added it to the list of invocations via AddDynamic.

1 Like

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

Privacy & Terms