Inspector Fields
| Field | Type | Description |
HUD | Transform | Root transform of the in-world HUD elements (health bars, indicators). Flipped alongside the sprite when the character changes horizontal direction. |
Properties
| Property | Type | Description |
position | Vector2 (get/set) | World-space position of the character. Reading returns transform.position; writing moves the character instantly. |
direction | Direction (get) | Current facing direction. Set via SetDirection(). |
health | Health (get) | The Health component on this character. Retrieved automatically on Awake. |
blocking | bool | Whether the character is currently in a blocking pose. Read by PlayerHealth and EnemyHealth before applying damage. |
damage | int (virtual get/set) | Damage this character deals per hit. Default: 1. Overridden by PlayerController (inventory-driven) and EnemyController (Inspector field). |
defense | int (virtual get/set) | Defense value subtracted from incoming damage. Default: 0. Overridden by subclasses. |
Events
| Event | Signature | Description |
OnInitialize | Action<ExecutionContext> | Fired at the end of Initialize(). Subscribe here from external components that need a reference to the character after it is fully set up. |
Methods
| Method | Description |
Initialize(ExecutionContext context, ExecutionContextElement parent) | Retrieves the Animator, AudioSource, and Health components, calls health.Initialize(), then fires OnInitialize. Called automatically by the InstructionRunner at level start. Override in subclasses to add further setup after calling base.Initialize(). |
SetDirection(Direction direction) | Updates direction and flips transform.localScale and HUD.localScale to mirror the sprite for left-facing movement. Up and Down directions leave the scale unchanged. |
PlayAnimation(string stageName) | Calls Animator.Play(stageName). Does nothing if the character is currently dead, preventing incorrect animation states from playing after death. |
Subclassing
Override Initialize() to run setup logic after the base class has wired up the animator, audio, and health. Always call base.Initialize() first. Override damage and defense to supply values from your own source (inventory, Inspector field, etc.):
public class MyCharacter : CharacterInstanceController
{
[SerializeField] int baseDamage = 2;
public override int damage => baseDamage;
public override void Initialize(ExecutionContext context, ExecutionContextElement parent)
{
base.Initialize(context, parent);
// additional setup here
}
}
ℹ️
CharacterInstanceController inherits from
ExecutionContextElement, which means every character is cloned at play start and the original scene instance is preserved for reset. Do not store references to the original instance from runtime code — always use the cloned instance provided by
Initialize().