HUDElement

Abstract base class for individual HUD panels. Subclass to create new HUD components that are auto-discovered and managed by the parent HUD container. Provides virtual lifecycle callbacks for activation and deactivation.

Definition

Namespace: Paragon.Townskeep.HUD Assembly: Townskeep.dll

public abstract class HUDElement : ParagonUIBehaviour

Inheritance: SerializedMonoBehaviourParagonBehaviourParagonUIBehaviour → HUDElement

Remarks

HUDElement is intentionally minimal — it provides a back-reference to the parent HUD and two lifecycle hooks. Subclasses should place their initialization logic in Unity's Awake()/Start() or in a custom Initialize() method, and use OnActivated()/OnDisabled() for visibility-related logic (e.g., refreshing displayed data, pausing animations).

The hud field is set by HUD.Awake() before any Start() calls, so subclasses can safely access hud in Start().

Quick Lookup

Goal
How

Create a new HUD panel

Subclass HUDElement and place on a child GameObject under HUD

React to HUD shown

Override OnActivated()

React to HUD hidden

Override OnDisabled()

Access parent HUD

Use this.hud

Access sibling element

hud.TryGetHUDElement<OtherElement>(out var other)

Fields

hud (protected)

Back-reference to the parent HUD container. Set by HUD.Initialize() during Awake(). Use this to access sibling elements via hud.TryGetHUDElement<T>().

Methods

Initialize

Called by the parent HUD during Awake(). Stores the back-reference.

Parameter
Type
Description

hud

HUD

The parent HUD container

OnActivated (virtual)

Called when the parent HUD is activated via HUD.Activate(). Override to refresh displayed data, start animations, or subscribe to events.

Default implementation: Empty (no-op).

OnDisabled (virtual)

Called when the parent HUD is disabled via HUD.Disable(). Override to pause animations, unsubscribe from events, or release resources.

Default implementation: Empty (no-op).

Extension Points

Optional Overrides

Method
Purpose

OnActivated()

React to HUD becoming visible

OnDisabled()

React to HUD being hidden

Implementation Requirements

When subclassing, you MUST:

  1. Place the component on a child GameObject under a HUD-bearing GameObject

  2. Mark the class as non-abstract (concrete)

You SHOULD:

  • Use OnActivated() to refresh UI state, not OnEnable() — the HUD may be enabled without Activate() being called

  • Access sibling elements through hud.TryGetHUDElement<T>() rather than GetComponentInParent or direct references

  • Use Unity's Awake() / Start() for one-time setup, and OnActivated() / OnDisabled() for repeated visibility changes

Common Pitfalls

circle-exclamation
circle-exclamation

Examples

Minimal HUD element

Accessing sibling elements

See Also

  • HUD — parent container that manages elements

  • ChatHUD — concrete element implementation for chat

Last updated