- These notes are starting at 1:53, Creating Widgets.
- I ended at 2:00
- First he builds a health bar.
- This uses the UI construction set called widgets.
- There is much more to this than he discusses here.
- Keep in mind how you set this up.
- Some systems do not attach this to the player.
- Like everything else, the widget is programmable in blueprint.
- He shows us a bad way to communicate between the widget and the player.
- He builds this functionality in the widget
-
- Note the GetPlayerPawn, then a cast to the right pawn.
- We are getting a pointer to the base class.
- Then casting it to the class we want.
- So we can get the class specific data.
- Note, we are not using getters and setters.
- This is driven the wrong way.
- It is called every tick.
- A better solution is to create an UpdateHealth.
- And only call it when we take damage or are healed.
- We continue to build functions.
- And he introduces parameters in a very casual way.
-
- Be careful renaming things.
- At one point I renamed a parameter.
- But it didn't catch it. So it couldn't compile.
- But the message was clear
-
- With a very clear indication of the problem in the widget.
-
- He gently introduces a "driver" as a "debug function".
- While he said not to apply health through the damage system, I quickly hooked this up as well.
-
- I Refactored my TakeDamage event
PlayerT::DamageEvent(damageEventData) {
UpdateHealth(damageEventData.damageAmount)
UpdateHealthBar()
CheckForDeath()
}
-
-
PlayerT::UpdateHealth(healthDelta) {
health = clamp(health+healthDelta, 0, defaultHealth);
}
-
-
PlayerT::UpdateHealthBar() {
HealthBar.UpdateHealth(health/defaultHealth);
}
-
-
PlayerT::CheckForDeath() {
if (health ≤ 0 and not isDead) {
isDead = true;
System.PlayerDied();
}
}
-