The Low-Tech AI Architecture of Elden Ring
The Low-Tech AI Architecture of Elden Ring
Elden Ring achieves its punishing and diverse NPC encounters not through complex planning algorithms, but through a relatively simple "low-tech" AI architecture. The system is primarily implemented in Havok Script (a games-oriented Lua implementation) and relies on a Pushdown Automaton (PDA) rather than a traditional Finite State Machine (FSM) or a complex Behavior Tree.
Goal-Based Pushdown Automaton
Elden Ring's AI is centered around the concept of a Goal, which is a unique state the AI can occupy. Unlike a standard Finite State Machine, which transitions from one state to another, FromSoftware uses a stack of goals, turning the system into a Pushdown Automaton.
How the Goal Stack Operates
Each frame, the Actor updates the Goal at the top of the stack. The execution flow follows these rules:
- Sub-Goals: A Goal can push new "Sub-Goals" onto the stack. The topmost Sub-Goal executes in the next frame.
- Return Values: A Goal's update function returns one of three values:
Continue,Success, orFailure. - Popping the Stack:
SuccessorFailurecauses the current Goal to be popped from the stack. - Unwinding: A
Failureresult causes the stack to unwind, popping all unexecuted Sub-Goals until it reaches the parent Goal.
This structure allows the AI to attempt a sequence of actions (like a combo attack) and gracefully return to a higher-level decision state if any part of that sequence fails.
Decision Making via the Activate Callback
The core AI logic resides in the activate callback, which is triggered when a Goal is first updated or when it exhausts its Sub-Goals and resumes execution.
Weighted Random Selection
To determine the next action, the AI typically uses a weighted random selection process. The activate function evaluates the current context—such as the distance to the player and the Actor's current health—and assigns weights to a list of possible actions.
For example, if a target is far away, the weight for an "Approach Target" goal is increased; if the target is close, the weight for a "Heavy Attack" increases. These weights can be further modified by cooldowns to prevent the AI from spamming the same move.
Reactive Behavior via Interrupts
To ensure NPCs respond immediately to player actions, the system employs an Interrupt mechanism. Interrupts bubble up from the currently executing Goal to its parents recursively until an interrupt is "consumed" (the callback returns true).
This allows for specific, "evil" behaviors, such as the Bell Bearing Hunter detecting a spell cast or item use and immediately aborting its current action to launch an attack. Interrupts can also be triggered by dynamic spatial watch regions, allowing a boss to react instantly if a player moves behind or underneath them.
Technical Implementation and Data Access
Animation-Driven Execution
Most of the AI's actual output is animation-driven. The Goal system tells the engine to play a specific animation, and the animation events themselves handle the hitbox timings, projectile creation, and special effect triggers.
Actor Data and Memory
Rather than using complex "blackboard" systems common in modern AI, Elden Ring uses a simple array of floats on each Actor. Goals read and write to these indices arbitrarily to store and retrieve state data.
Middleware Integration
FromSoftware relies heavily on Havok middleware:
- Havok Script: Used for AI logic.
- Havok Animation Studio: Used for authoring animations.
- Havok Physics: Handles collision and physics.
- Havok Navigation: Handles pathfinding.
Comparison with Other AI Architectures
FromSoftware's approach offers several advantages over more "high-tech" alternatives like Behavior Trees (BTs) or Goal-Oriented Action Planning (GOAP):
- Performance: A PDA is generally faster than a Behavior Tree because it executes a single Goal from the top of the stack rather than re-evaluating a complex tree of nodes from the root every frame.
- Simplicity: By using imperative code within states to handle control flow, FromSoftware avoids the "node explosion" often seen in large BTs or FSMs.
- Designer Control: This system keeps the sequence of actions firmly in the hands of combat designers and animators, rather than delegating the sequence to a search algorithm (as in GOAP or STRIPS).
"A 'weekend' long implementation of the structure used here (on top of a generic scripting language) is going to be basically sufficient to implement a game like Elden Ring."
Community Insights
While the author describes the system as "low-tech," some developers in the community argue that the complexity lies in the implementation of the individual goals (e.g., the physics and 3D spatial checks required for a successful "attack" goal) and the level design. One commenter noted that the perceived intelligence of the enemies is often a result of clever level design and aggro management rather than the AI logic itself.