Performance Tips
UI is often a silent performance killer in Unity. HookUI does a lot of optimization for you, but you can help it.
1. Canvas Splitting
Don't put everything under one massive Canvas.
- Dynamic UI: (Health bars, damage numbers) -> Separate Canvas.
- Static UI: (Backgrounds, Borders) -> Separate Canvas.
- HookUI Flows: HookUI handles
HookViews efficiently by disabling their Canvas Component when hidden. This prevents Unity from re-calculating the layout for hidden screens.
2. Graphic Raycasters
Every GraphicRaycaster on screen has a cost every frame (or every input).
- HookUI Automatic:
HookViewautomatically disables theGraphicRaycasterwhen the view is hidden. - Manual: If you have complex nesting, ensure you don't have Raycasters on objects that don't need interaction (like Images acting as backgrounds).
3. ID Lookups
HookUI uses string hashes for lookups internally in some places, but string comparisons in others.
- Cached: The database is loaded into memory. Lookups are fast (
DictionaryorHashbased). - Avoid: Don't call
HookUIDatabase.Instance.GetItems(...)every frame. Cache the result inStart().
4. Reuse Animation Presets
If several components share the same Show/Hide animation, save it once as a HookAnimationPreset asset instead of leaving the same values duplicated inline across many HookAnimatorComponents. This isn't a runtime hot-path win — the animation data itself is tiny — but it keeps a project with dozens of screens lighter to maintain and avoids inline HookAnimation blocks quietly drifting out of sync with each other.
5. Keep HookUIComponent Nesting Reasonable
HookUIComponent's SyncWithParent execution mode subscribes its PlayShow/PlayHide directly to the parent HookView's OnShowStarted/OnHideStarted events. Every synced sub-component under a view starts its own animation coroutine the moment the view begins showing or hiding. That's fine for a handful of panels, but stacking many synced components onto one screen means many coroutines kicking off at once on every transition. Keep sub-panel nesting reasonably flat, and consider Manual mode (calling PlayShow/PlayHide yourself) for anything that doesn't actually need to move in lockstep with the parent view.
6. One HookInAppNotifications Instance
HookInAppNotifications is a singleton (Instance) — its own Awake() destroys any duplicate GameObject that shows up after the first one is registered. Only ever place one in a scene (ideally on a persistent bootstrap object). A second instance doesn't cause a bug, but it's a wasted GameObject that gets destroyed on the spot.