Skip to content

NPC graphs

For creatorsAdd-on 2.2.2+

You bring the keeper to life: a shopkeeper who tidies her shop, notices you, greets you, talks with you, remembers you next time, and closes at six.

An NPC graph decides what a character does next. The add-on calls it a person graph. It is its own kind of graph, next to the behaviour graphs of game logic. The rest of the character is separate: the body moves it, its card shows what it says, and a dialogue page holds a conversation.

  1. Make the keeper. In the Kit panel of tutorial 28, press New Asset and choose NPC — someone people meet. Open the new asset. You get a complete NPC:

    Part What you get
    Body A wardrobe body named in her body tag
    Card Her name, tagline and greeting (agent_name, agent_tagline, agent_greeting) and her id, agent_id = npc:<name>
    Person graph A Simulacrum Person graph on the keeper
    The shop A counter she stands behind, a shelf, a display table, a stock box on a pallet, a stool, a shop sign, a counter bell, a door bell, and a spawn in front

    Her card tags are in Properties ▸ Object ▸ Simulacrum ▸ Components ▸ Person. Her Person Graph field and the Preview Body button (which shows her body in Blender, never exported) are in Properties ▸ Object ▸ Simulacrum ▸ Person.

  2. Open her graph. Open a node editor, choose Simulacrum Person, and pick her graph. It is named after her, such as Keeper NPC. Add ▸ Person has three kinds of node:

    • State: a name, and Runs When: how near a visitor must be for it to run (see Level of detail). Enter takes transitions in, Exit sends them out, and Do starts its chain of tasks.
    • Transition: a trigger and its value. From takes one or more states; leave it empty and it fires from any state. To goes to one state.
    • Task: what a state does when it starts, in chain order.
  3. Read her day. The keeper’s graph:

    idle ──6 s──▶ tidy (wander 0.7 m) ──arrived──▶ idle
    idle / tidy ──sees the visitor──▶ notice (faces you) ──loses you──▶ idle
    tidy ──hears the bell──▶ alert ("Be right with you!") ──2.5 s──▶ notice
    idle / tidy ──visitor within 2.6 m──▶ greet (waves, says her greeting) ──2 s──▶ attend (talk)
    attend ──done──▶ served ──visitor beyond 4 m──▶ idle
    greet / attend ──visitor beyond 4 m──▶ farewell ("Come back soon.") ──2.5 s──▶ idle
    any ──schedule: close (18:00)──▶ closing (to the sign) ──arrived──▶ flipping ──2 s──▶ closed
    closed ──visitor within 2.6 m──▶ sorry ("Sorry — we're closed. Back at nine!")
    closed / sorry ──schedule: open (09:00)──▶ idle
  4. Check the Person tab. In the node editor’s sidebar, the Person tab’s Person Graph panel holds the Initial State, the Fallback State, the level-of-detail distances, her senses, what she knows, her drives, her schedule and her memory. At the bottom it says how many states and transitions will export, or what to fix: a transition that goes to two states, two states with one name, or an initial state that doesn’t exist.

  5. Give her a conversation. Her attend state has a Talk task that opens her dialogue page. Open a node editor, choose Simulacrum Dialogue and pick her page, such as Keeper Talk. Add ▸ Dialogue has:

    • Line: something she says.
    • Choice: up to six options, each its own output. One option can take free text.
    • Mind: the agent behind her answers, in her persona (agent_persona), from the node’s Prompt and what you chose.
    • Set and Condition: store a value, and branch on it.
    • End: the conversation ends, and her person graph hears done.

    Her lines and your choices appear on her speech card, in the scene beside her, so a headset sees it too. Choose with a click or a tap, the keys 1–6, or a controller’s ray.

  6. Let her remember you. In the Person tab, Memory lists her variables: a name, a default, and Saved (kept in the player’s save, so it survives the visit). Remember (Set) and Remember (Add) tasks change a variable, and a transition’s When fires only if a variable is true, equals a value, or is at least a number. The keeper remembers met and counts visits: come back after you’ve talked, and she says “Welcome back!”

  7. Give her senses. In the Person tab, set Sight Field (°), Sight Range (m) and Hearing Range (m). The keeper sees 140° to 10 m and hears to 12 m. On Sight and Lose Sight (topic visitor) fire as you come into view with a clear line and leave it; a shelf’s back panel blocks her view, a counter below eye height doesn’t. Hears a Noise fires when a noise source rings within range. The door bell is an empty with Add Component ▸ Characters & People ▸ Noise Source: walking into its radius rings it.

  8. Let her walk. An anchor is a named place: an empty with Add Component ▸ Characters & People ▸ Walk-To Spot, facing the way she should face there. A Go To task walks her to it, round the counter, not through it. Walk Home and Wander use the same paths. If there is no way there, the Exception trigger fires (topic unreachable, or no-anchor when the scene lacks the anchor).

  9. Give her opening hours. Every scene has a clock: clock.start is the hour it starts at, and clock.rate is game hours per real hour (60: a game hour each real minute). In the Person tab, Schedule lists entries: At (h), a name, and the memory variable it Sets. As the clock passes an entry, the Schedule trigger fires with the entry’s name as its topic. An NPC that arrives after closing is already closed. A scene on the shared world clock uses that instead; see time of day.

  10. Let her use things. The shop sign is a smart object: Add Component ▸ Smart Objects ▸ Smart Object with the states open,closed, the use flip and the label Flip the sign, plus a look per state (State Look) and a place to stand (Use Spot). A Use task makes her walk to the use spot and use it; then her graph hears used. You use it too: look at it and press E. Smart things lists every smart object setting.

  11. Let her carry and sit. The stock box is a Carryable, the display table and pallet are Place objects with a Place spot, and her stool is a Seat. Take, Put and Drop tasks carry the box; a Sit task sits her down. Every second tidy, she fetches the box from the pallet, carries it round the counter to the display, and carries it back. Between rounds she rests on her stool.

  12. Press ▶ Play and walk up to her. Across the shop she notices you and turns to watch. Come close and she walks to her post, waves, says “Hello — welcome in.” and shows her card, and the talk begins. Walk away and she says “Come back soon.”

While Play runs, the node editor outlines the state she is in, and the Person tab shows it live.

How much of a character is awake depends on how near the nearest visitor is. Each state’s Runs When says how near that must be:

Runs When When it runs The keeper
Full A visitor is within Full Behaviour Within (m) Within 12 m: she greets, attends and says goodbye
Ambient A visitor is within Ambient Behaviour Within (m) Within 40 m: she only idles and tidies
Always Even with nobody near Beyond 40 m she is dormant. She has no Always states, so she holds her post and nothing happens
Mind The agent behind her is answering A conversation’s Mind node is waiting for the agent’s answer

A transition into a state that can’t run at the current distance doesn’t fire. When the visitor moves too far for the current state, she goes to her fallback state: walk away mid-greeting and she is back to idle. Set the two distances in the Person tab: Full Behaviour Within (m) and Ambient Behaviour Within (m).

Trigger Fires when
After (s) She has been in the state this long
Message A topic arrives: arrived when a walk ends, used after a use, done when a talk ends
Visitor Within (m) · Visitor Beyond (m) The nearest visitor comes this near, or goes this far
On Sight · Lose Sight She sees someone, or loses them for a second
Hears a Noise A noise within her hearing (topic: the noise’s kind, * for any)
Exception Something she tried failed: unreachable, no-anchor, no-object, busy, unknown, hands-full, empty-handed, full
Schedule The clock passes a schedule entry (topic: its name)
Health At or Below A value drops to this
Learns of a Thing · A Drive Rises Past See Going further
Task What it does
Play Clip A one-off clip of the body, such as Wave
Wander · Walk Home · Go To Walk within a radius of her post, back to it, or to an anchor
Face The visitor, her post’s facing, or the last noise
Say · Show Card A line on her card (empty: her greeting); her name, tagline and line
Talk · Ask the Mind Open a dialogue page; ask the agent behind her
Remember (Set) · Remember (Add) Change a memory variable
Use · Take · Put · Drop · Sit Use a smart object, carry one, or sit
Choose Pick the best use for her needs (see below)
  • What she knows. Set Knows in the Person tab to Only what it perceives, and she knows only the smart objects she has seen or heard. A starting list, then perceived adds a few she knows from the start. A Use with nothing known fails with unknown, and Learns of a Thing fires when she discovers one, so she can wander until she finds what she needs.
  • Needs and choices. Give her Drives in the Person tab (a name, where it starts, how fast it builds, how much she cares), and let smart objects advertise what a use satisfies, such as smart.use.satisfies = rest:60 on a bench. A Choose task weighs every use she knows against her drives, minus the walk, and makes the best one. A Drive Rises Past fires when a need builds up.
  • Behaviours that come with objects. A smart object can carry a small person graph of its own for its use (order, then drink, at a coffee stand). Set it as the object’s Use Behaviour in Properties ▸ Object ▸ Simulacrum ▸ Smart Use; New makes a starter that uses the object, then is done. Any NPC that makes that use runs it.
  • Roles. A Role on a person retunes a shared graph without copying it: what it knows, its layers, and its drives. One graph can play a barista and a guard.
  • Layers. A smart object sits on a layer (smart.layer: world, player or hidden). An NPC perceives only its graph’s Layers. An item tagged smart.grants = perceive:player lets whoever holds it perceive the player layer too, like a pair of glasses that reveals a quest marker.

The Role box is in Properties ▸ Object ▸ Simulacrum ▸ Person, under the Person Graph field.

Nav mesh for people. In a scene that isn’t a horde, Properties ▸ World ▸ Simulacrum ▸ Nav Mesh ▸ Bake builds a nav mesh of polygons that NPCs walk: steps, ramps, stairs and upper floors. Smart objects are used, never walked on. Tag any other object nav.walk = no to keep NPCs off its top. Only what an NPC can reach from the spawn and the NPC posts is kept. The bake needs Node.js on your computer; the panel says so when it is missing.

Build (or the Kit panel’s Release) ships her graph with her, so it is part of her version, and Release signs it with her. A change to the graph is a new version; a new behaviour makes a good minor release.

To give NPCs a home where they keep living while nobody watches, see people.