Goal

The objective was to create a robust NPC behaviour system that dynamically reacts to in-game conditions such as time of day, weather, and day of the week. The system needed to handle complex, varying schedules for different NPCs, integrate seamlessly with the existing Dynamic Climate System, and remain flexible enough to add new behaviours without rewriting core logic.

System Overview

The NPC Behaviour System is built around a modular architecture using MonoBehaviours, ScriptableObjects, and persistent mediator classes to control and track NPC actions.

  • Time-dependent: NPCs follow schedules based on the in-game clock.

  • Weather-aware: Outdoor actions are skipped or replaced during bad weather.

  • Day-specific: Behaviours can be restricted to certain weekdays.

  • Persistent State: Actions can continue or transition smoothly even when the player changes scenes.

Architecture

The system uses a multi-layered approach:

  1. Behaviour Selection Layer – Decides which action to run based on time, weather, and day conditions.

  2. Action Execution Layer – Runs the logic for the current NPC action.

  3. Persistence Layer – Maintains action states across scenes and coordinates transitions.

Component Breakdown

NPCAction (Base Class)

  • Attached to NPC prefabs.

  • Defines Initialize() and DoAction() for executing behaviours.

  • Extensible into different actions (DialogueAction, PatrolAction, MultiBehaviourAction, GoToDestinationAction).

  • Allows designers to add new actions without modifying the core behaviour system.

NpcBehaviour (ScriptableObject)

  • Stores a list of NpcTasks, each containing:

    • An NpcAction reference

    • Time range

    • Weather restrictions

    • Fallback behaviour indexes for weather changes

  • Handles the selection logic for the next action, considering:

    • Current time

    • Current weather

    • Allowed days of the week

    • Whether the previous action has finished or can be skipped

NpcBehaviourControl (Controller)

  • Attached to the NPC GameObject.

  • Holds multiple NpcBehaviour objects for different contexts (e.g., weekday vs weekend).

  • Selects the first valid behaviour during initialization.

  • Calls UpdateAction() to drive action execution every frame.

Persistence Components

  • NpcTaskState: Tracks individual action progress (started, finished, skippable, scene).

  • NpcTaskMediator: Wraps NpcTaskState and provides getter/setter methods for safe state changes.

  • NpcSceneMediatorSO: ScriptableObject that:

    • Tracks NPC activity per scene

    • Resets states on scene change

    • Moves NPCs to their next scheduled action, even across scenes

Result

  • Fully modular & designer-friendly – Designers can create and modify quests without programming.

  • Supports branching logic – Quests can have multiple start/finish points.

  • Dynamic prerequisite checks – Ensures quest flow feels natural and respects progression rules.

  • Extensible step system – Adding new quest types requires no changes to the core system.

Key Takeaways

  • Modularity – Separating actions from behaviour logic allows for fast iteration and expansion.

  • Event + Data Driven – Time, weather, and day-of-week rules are stored in data, making it easy for designers to change behaviour without code changes.

  • Persistence Matters – Mediator classes ensure the system works seamlessly across multiple scenes.

  • Failover Logic – Weather-based action fallbacks keep NPCs active and believable even when conditions change.

  • Maintainability – Clear division between action logic, behaviour selection, and state persistence keeps the system clean and scalable.

Actions Examples

What I Learned

  • Separation of Core Logic – Built a flexible base NPCAction class that can be extended into different actions, allowing designers to add new behaviours without altering core code.

  • Scene-Wide Data Persistence – Learned that ScriptableObjects are an effective way to manage and persist complex NPC states across multiple scenes.

  • Time & Condition-Based Scheduling – Refined my approach to combining in-game time, day-of-week, and environmental factors like weather into a cohesive, dynamic NPC schedule.

  • Decoupling Conditions from Actions – Separated behaviour conditions (weather, time range, etc.) from the actions themselves, enabling reuse of the same action under different behaviour conditions.

Day-Specific NPC Routines Examples

Scene-to-Scene NPC Schedule Transitions

Scene-to-Scene NPC Schedule Progression