QuestForge Runtime Setup

QuestForgeRuntimeSetup.cs

Overview

QuestForgeRuntimeSetup is the scene-level initialisation component for the Quest Forge system. It serves two distinct responsibilities:

  1. Shared Transform Injection — Populates shared Malbers TransformVar ScriptableObject assets with the runtime player and camera transforms. Every system that needs to know where the player or camera is (QuestManager, POIManager, MinimapUI, CompassBarUI, QuestEventReporter, etc.) references these shared TransformVar assets rather than performing their own lookups. This component is the single place those assets get their values at runtime.

  2. Save System Bootstrap — After all Start() methods in the scene have executed, it calls QuestSaveSystem.LoadGame() to restore quest and dialogue state, then notifies every QuestTrigger and DialogueTrigger in the scene to re-evaluate whether they should be deactivated or destroyed based on that loaded state.

This component should be placed on a persistent scene manager GameObject, typically as part of the QuestForgeManagers prefab.

Inspector Properties

Shared Variables

Property
Description

Player Transform Var

The TransformVar ScriptableObject asset that all Quest Forge systems use to find the player. This component writes to it at Start; other systems read from it.

Main Camera Transform Var

The TransformVar ScriptableObject asset that UI systems (minimap, compass, world-space labels) use to find the main camera.

Auto-Find Settings

Property
Description

Auto Find Player

When enabled, searches for a GameObject with the specified tag and assigns its Transform to Player Transform Var.

Player Tag

The Unity tag used to locate the player. Default is "Player".

Auto Find Camera

When enabled, uses Camera.main to find the main camera and assigns its Transform to Main Camera Transform Var. Requires the scene camera to be tagged "MainCamera".

Manual References (Optional)

Property
Description

Manual Player Transform

A directly assigned player Transform. Takes priority over Auto-Find if set.

Manual Camera Transform

A directly assigned camera Transform. Takes priority over Auto-Find if set.

Priority order: Manual Reference → Auto-Find. If a manual reference is assigned, auto-find is skipped entirely for that target.

Save System Integration

Property
Description

Auto Load On Start

When enabled, automatically calls QuestSaveSystem.LoadGame() at scene start to restore all saved quest and dialogue state.

Auto Load Delay

Seconds to wait before loading. Set to 0 for immediate load (runs at end of frame, after all Start() methods). Any value above 0 uses Invoke with the specified delay.

Debug

Property
Description

Debug Mode

Enables detailed log output via QuestLogger for all initialisation steps.


How It Works

Transform Initialisation

On Start(), the component resolves the player and camera transforms in the following order for each:

  1. If a Manual Reference is assigned, use it directly

  2. Otherwise, if Auto-Find is enabled, search by tag (GameObject.FindGameObjectWithTag) or Camera.main

  3. If a transform is found, write it into the corresponding TransformVar ScriptableObject

Because TransformVar is a ScriptableObject, any other component that holds a reference to the same asset instantly sees the updated value — no scene coupling required.

Save System Bootstrap

When Auto Load On Start is enabled and no delay is set, the load runs inside a coroutine that waits for WaitForEndOfFrame. This guarantees that every component's Start() method has finished executing before the save data is applied. This is important because QuestTrigger and DialogueTrigger components initialise their trigger IDs in Start() — if the save loaded before that, the ID lookup would fail.

The load sequence is:

  1. Verify QuestSaveSystem.Instance is available (retries every 0.1s if not yet ready)

  2. Call QuestSaveSystem.Instance.LoadGame()

  3. If successful, call NotifyTriggersToRecheck() — finds every QuestTrigger and DialogueTrigger in the scene and calls RecheckSavedState() on each

  4. Each trigger checks whether its unique ID appears in the loaded save data and applies the appropriate state (destroy, deactivate, or mark as already triggered)


Public API

Method
Description

SetPlayer(Transform newPlayer)

Updates Player Transform Var with a new transform at runtime. Use for character switching or late-spawned players.

SetCamera(Transform newCamera)

Updates Main Camera Transform Var with a new transform at runtime. Use when switching between cameras.

GetPlayerTransform()

Returns the Transform currently stored in Player Transform Var, or null if not set.

GetCameraTransform()

Returns the Transform currently stored in Main Camera Transform Var, or null if not set.

RefreshPlayer()

Re-runs the player initialisation logic (manual check → auto-find). Use when the player spawns after Start().

RefreshCamera()

Re-runs the camera initialisation logic. Use when the main camera changes after Start().

ManualLoadSavedData()

Manually triggers the full save load sequence. Can be bound to a UI button or called from code.


Custom Inspector (Play Mode)

When the scene is running, the Inspector shows a live status panel with:

  • Current Player — the name of the transform currently in Player Transform Var

  • Current Camera — the name of the transform currently in Main Camera Transform Var

  • Refresh Player / Refresh Camera buttons — re-runs the respective initialisation without restarting the scene

  • Load Saved Data button — manually triggers a full save load

  • Save Current Data button — manually calls QuestSaveSystem.Instance.SaveGame()

  • Live counters — Active Quests, Completed Quests, Dialogue Triggers Completed, Quest Triggers Activated


Setup Instructions (ONLY PERFORM IF NEEDED)

triangle-exclamation
  1. Create two TransformVar ScriptableObject assets (e.g. Runtime_PlayerTransform and Runtime_MainCamera). These live in your project as assets, not in the scene.

  2. Assign both assets to this component's Shared Variables fields.

  3. Assign the same assets to every other system that needs them: QuestManager.Player Transform, POIManager.Player Transform, MinimapUI.Player Transform, CompassBarUI.Player Transform, QuestEventReporter.Player Transform, etc.

  4. At runtime, QuestForgeRuntimeSetup writes to those assets once, and all systems automatically have a valid reference.


Other Notes

  • This component does not use DontDestroyOnLoad. It is a scene-level component. If you load a new scene, a fresh instance of this component should be present in that scene to re-initialise the TransformVar assets for the new scene's player and camera.

  • If Auto Load Delay is set to 0, the load still runs one frame after all Start() methods via WaitForEndOfFrame — it is not truly immediate. This is by design to prevent timing conflicts with trigger ID initialisation.

  • QuestSaveSystem initialises in Awake. If for any reason it is not ready when LoadSavedData() runs, the method retries automatically every 0.1 seconds until it becomes available.

  • NotifyTriggersToRecheck() uses FindObjectsOfType<QuestTrigger>() and FindObjectsOfType<DialogueTrigger>(). This is a scene-wide search and may have a minor performance cost on scenes with large numbers of triggers — it only runs once per load.

Last updated