---
key: lesson/npc-action-selection
type: lesson
id: npc-action-selection
lang: en
title: How an NPC selects an action
summary: >-
  Separate eligibility, priority and execution so a character makes explainable
  decisions without rapidly switching between them.
updatedAt: '2026-10-20'
status: active
url: 'https://gamemechanics.pro/en/lessons/npc-action-selection/'
jsonUrl: 'https://gamemechanics.pro/api/v1/knowledge/en/lesson/npc-action-selection.json'
markdownUrl: 'https://gamemechanics.pro/content/knowledge/en/lesson/npc-action-selection.md'
aliases: []
tags:
  - npc-ai
  - decision-making
  - debugging
sourceIds:
  - source-25e079ce502c5d9b
  - source-8ad8c2778e5aab6e
sources:
  - id: source-25e079ce502c5d9b
    title: 'Dawe et al.: Behavior Selection Algorithms, An Overview'
    url: >-
      https://www.gameaipro.com/GameAIPro/GameAIPro_Chapter04_Behavior_Selection_Algorithms.pdf
    verifiedAt: null
  - id: source-8ad8c2778e5aab6e
    title: 'David Rez Graham: An Introduction to Utility Theory'
    url: >-
      https://www.gameaipro.com/GameAIPro/GameAIPro_Chapter09_An_Introduction_to_Utility_Theory.pdf
    verifiedAt: null
relations:
  - type: requires
    direction: outgoing
    label: Before you start
    key: lesson/npc-perception
    title: NPC perception and target memory
    url: 'https://gamemechanics.pro/en/lessons/npc-perception/'
    jsonUrl: 'https://gamemechanics.pro/api/v1/knowledge/en/lesson/npc-perception.json'
    markdownUrl: 'https://gamemechanics.pro/content/knowledge/en/lesson/npc-perception.md'
  - type: explains
    direction: outgoing
    label: Apply the principle
    key: mechanic/point-and-click--family-31
    title: 'NPC, animal and living-system behavior'
    url: >-
      https://gamemechanics.pro/en/knowledge/mechanic/point-and-click--family-31/
    jsonUrl: >-
      https://gamemechanics.pro/api/v1/knowledge/en/mechanic/point-and-click--family-31.json
    markdownUrl: >-
      https://gamemechanics.pro/content/knowledge/en/mechanic/point-and-click--family-31.md
  - type: practices
    direction: outgoing
    label: Put it into practice
    key: practice/maintenance-patrol
    title: Maintenance patrol
    url: 'https://gamemechanics.pro/en/knowledge/practice/maintenance-patrol/'
    jsonUrl: >-
      https://gamemechanics.pro/api/v1/knowledge/en/practice/maintenance-patrol.json
    markdownUrl: >-
      https://gamemechanics.pro/content/knowledge/en/practice/maintenance-patrol.md
  - type: reviews
    direction: outgoing
    label: Review through a lens
    key: lens/schell-031
    title: Action
    url: 'https://gamemechanics.pro/en/knowledge/lens/schell-031/'
    jsonUrl: 'https://gamemechanics.pro/api/v1/knowledge/en/lens/schell-031.json'
    markdownUrl: 'https://gamemechanics.pro/content/knowledge/en/lens/schell-031.md'
  - type: reviews
    direction: outgoing
    label: Review through a lens
    key: lens/schell-062
    title: Transparency
    url: 'https://gamemechanics.pro/en/knowledge/lens/schell-062/'
    jsonUrl: 'https://gamemechanics.pro/api/v1/knowledge/en/lens/schell-062.json'
    markdownUrl: 'https://gamemechanics.pro/content/knowledge/en/lens/schell-062.md'
  - type: contains
    direction: incoming
    label: Learning paths
    key: path/npc-behavior
    title: NPC behavior
    url: 'https://gamemechanics.pro/en/learn/npc-behavior/'
    jsonUrl: 'https://gamemechanics.pro/api/v1/knowledge/en/path/npc-behavior.json'
    markdownUrl: 'https://gamemechanics.pro/content/knowledge/en/path/npc-behavior.md'
placements: []
supersededBy: []
attributes:
  category: engineering
  level: intermediate
  minutes: 6
endsAt: null
provenance: >-
  Original gamemechanics.pro material. Check illustrative examples in your own
  project.
license: CC-BY-4.0
codeLicense: MIT
attribution: gamemechanics.pro contributors
---
# How an NPC selects an action

id: npc-action-selection
type: lesson
key: lesson/npc-action-selection
lang: en
status: active
url: https://gamemechanics.pro/en/lessons/npc-action-selection/

Separate eligibility, priority and execution so a character makes explainable decisions without rapidly switching between them.

## Prerequisites

A character may need charging, repairs and helping the player simultaneously. Write the selection rule explicitly before adding behavioral architecture.

## The principle

First filter eligible actions, then select one, then execute it. Do not let each subsystem independently control movement. The Game AI Pro overview compares state machines, behavior trees and other selection methods; there is no universal winner.

A state machine suits a few distinct modes. A behavior tree suits sequences of conditions and actions. Comparing situational value can use a common scoring scale, as described in the utility-theory chapter. Scoring does not replace prohibitions or eligibility checks.

<span id="example-a-maintenance-robot"></span>

## Practical example

### A maintenance robot

In this teaching model, a robot can charge, repair a pump or help the player open a heavy door. Battery is normalized from 0 to 1. Below 0.1, a mandatory rule sends it to an available charger. If no route exists, it waits safely and reports why.

Otherwise, compare eligible candidates:

| Action | Score in this model | Eligibility                             |
| ------ | ------------------- | --------------------------------------- |
| Charge | `1 - battery`       | Charger reachable                       |
| Repair | `leakSeverity`      | Parts available and pump reachable      |
| Help   | `requestUrgency`    | Request still active and door reachable |

All inputs are bounded to 0..1. With battery 0.6, leak severity 0.8 and urgency 0.5, repair wins. These are authored design scores, not measurements of human desires.

To prevent close scores causing rapid switching, retain the current action until a competitor scores at least 0.15 higher. Release completed or ineligible actions immediately. Break ties with a stable order. Tune the margin after observation; the mandatory low-battery rule still takes priority.

## Common mistakes

- Comparing distance in meters with urgency on a 0..1 scale without conversion.
- Restarting repair every frame and resetting its progress.
- Retaining an action for stability after its target has been destroyed.

## Verify it

- Log inputs, excluded actions, scores and selection reasons.
- Check tied scores, lost targets and no eligible candidates.
- Vary urgency around the margin and check for excessive switching.
- Separately check mandatory charging and an unreachable charger.

## Prompt for an AI agent

> Implement selection as a pure function of a world snapshot and current action. Keep execution separate. Prepare a boundary-case table and explain every result without random selection. Do not connect a language model to per-frame control.

Review through the [Action](/en/lenses/#schell-031) and [Transparency](/en/lenses/#schell-062) lenses.

## Connected materials

- Before you start: [NPC perception and target memory](https://gamemechanics.pro/en/lessons/npc-perception/) (key: lesson/npc-perception)
- Apply the principle: [NPC, animal and living-system behavior](https://gamemechanics.pro/en/knowledge/mechanic/point-and-click--family-31/) (key: mechanic/point-and-click--family-31)
- Put it into practice: [Maintenance patrol](https://gamemechanics.pro/en/knowledge/practice/maintenance-patrol/) (key: practice/maintenance-patrol)
- Review through a lens: [Action](https://gamemechanics.pro/en/knowledge/lens/schell-031/) (key: lens/schell-031)
- Review through a lens: [Transparency](https://gamemechanics.pro/en/knowledge/lens/schell-062/) (key: lens/schell-062)
- Learning paths: [NPC behavior](https://gamemechanics.pro/en/learn/npc-behavior/) (key: path/npc-behavior)

## Sources and provenance

Original gamemechanics.pro material. Check illustrative examples in your own project.

- [Dawe et al.: Behavior Selection Algorithms, An Overview](https://www.gameaipro.com/GameAIPro/GameAIPro_Chapter04_Behavior_Selection_Algorithms.pdf) (id: source-25e079ce502c5d9b)
- [David Rez Graham: An Introduction to Utility Theory](https://www.gameaipro.com/GameAIPro/GameAIPro_Chapter09_An_Introduction_to_Utility_Theory.pdf) (id: source-8ad8c2778e5aab6e)

CC-BY-4.0 · gamemechanics.pro contributors
