Navmesh Ghost Manager

Use the NavMesh Ghost Manager demo pattern when you want Time Crystal ghosts that follow NavMesh paths, loop cleanly, and survive save/load cycles through INavMeshGhostManager.

Overview

NavMeshGhostManager is a demo-oriented scene controller that implements INavMeshGhostManager to showcase Crystal Save's NavMesh-aware ghost playback. It wires UI buttons, a TimeMachineRecorder, and ghost prefabs to spawn, loop, and despawn ghosts while keeping the save system informed about every instance.

Although the manager is convenient, it is not required for creating or controlling Time Crystal ghosts in your own gameplay systems. The interface and demo provide a reference implementation you can replace with custom logic that better fits your project.

Relationship to Time Crystal Presets

Time Crystal ghosts depend on a Time Machine configuration preset that enables Ghost Mode (recording during playback) and its supporting animation options. Set this preset inside the Crystal Save Settings window so that Save Settings apply the correct ghost-capable configuration automatically.

Pick a preset such as Ghost Racing (or any preset with Ghost Mode enabled) before testing NavMesh ghosts. Without it, recordings will not allow simultaneous playback and capture, and ghost-specific animation settings will remain disabled.

Core Responsibilities

NavMeshGhostManager takes care of the repetitive setup needed for NavMesh ghosts:

  • Synchronizes the player TimeMachineRecorder and its auto-start behavior, then displays the current recording state through UI controls.

  • Spawns and tracks ghost prefabs, optionally injecting a GhostNavMeshController and playback animation mode for each instance.

  • Maintains NavMeshGhostData collections so INavMeshGhostManager consumers can save, restore, or prune ghost instances on demand.

If you implement your own manager, mirror these responsibilities so RememberNavMeshGhost and other persistence components can discover an INavMeshGhostManager at runtime.

Working with GhostPlaybackComponent

Every spawned ghost uses GhostPlaybackComponent to drive recorded timelines. The component automatically detects whether a IGhostNavMeshController is present and switches between direct transform interpolation and NavMesh-driven playback. It also removes recording components and initializes smoothing so ghosts never re-record themselves.

GhostPlaybackComponent manages runtime path rendering and defers NavMesh-specific visualization to IGhostNavMeshController, preventing duplicate line renderers for NavMesh ghosts.

Reverse Playback Hooks

When the playback speed becomes negative, GhostPlaybackComponent asks an optional local GhostReverseAnimator to swap animation clips, enabling reverse playback while keeping locomotion natural. Returning to a positive speed restores the original clips automatically.

Working with GhostNavMeshController

GhostNavMeshController converts recorded samples into NavMesh waypoints, drives a NavMeshAgent, and optionally smooths closed loops or dynamic speed changes. It reads shared Save Settings when useGlobalSettings is enabled, so switching presets in the Remember Me window immediately affects every ghost that relies on global configuration.

The controller also detects GhostReverseAnimator on the same GameObject and logs its availability. During reverse playback it adjusts rotation and animator speed values so the agent keeps facing the direction of travel even while navigating the waypoint list backwards.

Working with GhostReverseAnimator

GhostReverseAnimator is a lightweight helper that maps forward animation clips to pre-authored reverse variants. GhostPlaybackComponent and GhostNavMeshController do not manipulate animations directly; instead they request reverse playback through this component so you can decide which clips should flip, which should stay forward, and how fallbacks are resolved.

The component lazily builds an AnimatorOverrideController when reverse playback is requested, applies mapped clips, and restores the original controller when returning to forward playback. You can extend the provided ReverseAnimationMap asset to cover any clip pairs your project requires.

Save/Load Integration via INavMeshGhostManager

INavMeshGhostManager defines the touchpoints between ghost demo managers and the persistence layer:

  1. Register and unregister ghosts as they spawn or despawn so save files know which GameObjects to serialize.

  2. Report recording state and provide the player recorder so the save system can store playback timelines alongside ghost metadata.

  3. Restore ghosts after loading by instantiating prefabs that match each NavMeshGhostRestoreInfo payload (playback mode, branch, loop state, and prefab reference).

NavMeshGhostManager's implementation is intended for sample scenes, but any production-ready manager can implement the same interface to achieve seamless save/load behavior for NavMesh ghosts.

Adapting the Pattern

When designing your own ghost workflow:

  • Keep the NavMesh-specific logic (GhostNavMeshController) on the ghost prefab so your manager only handles spawning and registration.

  • Provide a GhostReverseAnimator only when your animation library includes dedicated reverse clips—otherwise the playback system simply reuses the forward clips.

  • Use the Remember Me settings window to experiment with presets. Switching from Ghost Racing to Linear Replay is a quick way to understand which options each preset toggles for you.

By separating playback, navigation, animation, and save/load concerns across these components, you can scale from the demo manager to bespoke gameplay scenarios without rewriting the core Time Crystal ghost infrastructure.

Last updated