Skip to content

🧠 Health — Rule Hubs

📦 Folder Overview

This folder contains hub components that orchestrate rule execution for Health.

Currently includes:

  • DamageRuleHub
  • HealRuleHub

These hubs bridge rule contracts (IDamageRule, IHealRule, IPostDamageRule, IPostHealRule) with the HealthSystem that consumes them.


🎯 Purpose

Rule hubs exist to:

  • Discover local rule components
  • Cache them for runtime execution
  • Execute PRE rules in a deterministic order
  • Invoke POST observers after evaluation

Without a hub, local rule components are not automatically orchestrated.


🧩 What Lives Here

DamageRuleHub

Aggregates:

  • IDamageRule (PRE)
  • IPostDamageRule (POST)

Behaviour:

  • Caches PRE and POST rule components on the same GameObject
  • Sorts PRE rules in ascending Priority
  • Executes PRE rules in order
  • Invokes POST observers when notified by the consuming system

Notes:

  • PRE processing stops if a rule returns false or DamageContext.Cancelled is set
  • Exceptions from individual rules are caught and logged
  • Remaining rules continue unless execution has been explicitly stopped

HealRuleHub

Aggregates:

  • IHealRule (PRE)
  • IPostHealRule (POST)

Behaviour:

  • Caches PRE and POST heal rule components on the same GameObject
  • Sorts PRE rules in ascending Priority
  • Executes PRE rules in order
  • Invokes POST observers when notified by the consuming system

Notes:

  • PRE processing stops if a rule returns false or HealContext.Cancelled is set
  • Exceptions from individual rules are caught and logged
  • Remaining rules continue unless execution has been explicitly stopped

⚠️ Important Notes

Refresh Behaviour

Both hubs support:

Refresh()

Use when rule components are added, removed, or enabled at runtime.

Hubs also refresh during:

  • Awake()
  • OnEnable()

Execution Model

PRE stage

  • Reads cached rule array
  • Runs in ascending Priority
  • Mutates incoming context
  • May stop execution early

POST stage

  • Reads cached observer array
  • Invokes observers in cached component order
  • Exceptions are isolated and logged

POST execution timing is controlled by the consuming system.


Boundaries

Hubs should not:

  • Contain gameplay logic
  • Replace rule components
  • Assume cross-object orchestration
  • Become global registries
  • Bypass the consuming Health pipeline

Hubs coordinate execution only.


🧠 Usage Guidance

  • Add hubs to the same GameObject as HealthSystem
  • Keep hubs local and focused on orchestration
  • Use rules to define behaviour; use hubs to execute them

  • Rules Overview
  • Damage Rules
  • Heal Rules
  • Rules Abstractions