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 : ParagonUIBehaviourInheritance: SerializedMonoBehaviour → ParagonBehaviour → ParagonUIBehaviour → 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
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.
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
OnActivated()
React to HUD becoming visible
OnDisabled()
React to HUD being hidden
Implementation Requirements
When subclassing, you MUST:
Place the component on a child GameObject under a
HUD-bearing GameObjectMark the class as non-abstract (concrete)
You SHOULD:
Use
OnActivated()to refresh UI state, notOnEnable()— the HUD may be enabled withoutActivate()being calledAccess sibling elements through
hud.TryGetHUDElement<T>()rather thanGetComponentInParentor direct referencesUse Unity's
Awake()/Start()for one-time setup, andOnActivated()/OnDisabled()for repeated visibility changes
Common Pitfalls
Do not call Initialize() manually
Initialize() is called automatically by HUD.Awake(). Calling it again will overwrite the hud reference, which is harmless but unnecessary.
hud is null before Awake() completes
If your subclass accesses hud in its own Awake(), it may be null depending on script execution order. Use Start() instead, which is guaranteed to run after all Awake() calls.
Examples
Minimal HUD element
Accessing sibling elements
See Also
Last updated