24 · Templates and Frameworks | Generative AI for Game Development

The video argues that you should stop building narrative systems from zero. It covers a JSON scene schema, a Python engine, Twine passages and a six-step Unity kit that all share the same data.

3:27 video3 min readWatch on YouTube

Every new narrative game tempts a developer to write the story system from scratch. This video, chapter 24 of the companion series to Generative AI for Game Development by Shesh Narayan Gupta, argues for the opposite: build reusable templates and frameworks that adapt to any genre, mood or storytelling style. Its motto is build once, reuse forever, and it covers three areas: Python and JSON templates, Twine structures and Unity starter kits.

The JSON narrative schema

The first template treats scenes as nodes. Each node holds its text, its choices, emotion modifiers, AI prompt context and dynamic variables. Because content is kept separate from code, you can swap scenes, localize dialogue and scale to hundreds of nodes without touching the engine. The video summarizes the idea as data tells the story, code runs the machine: change the JSON and the game changes, with no recompile.

The Python story engine

The second template is a modular, readable and extensible Python engine. Its loop is simple: load the JSON, render the current scene, update the emotional state, present the choices and follow the chosen branch. The video's case study is a sci-fi mystery in which the player is a deep space engineer receiving fragmented messages from a vanished crew. The player's interpretations shape both plot outcomes and emotional tone. The design also includes fallback text, so the game degrades gracefully when the AI is unavailable.

Twine as the visual front end

Twine supplies a visual layer for the same data. Each passage maps to a story node. Using Harlowe or SugarCube with JavaScript, the story loads the same JSON at runtime, tracks player state and emotions across passages, and builds branching paths that mirror the Python engine. The JSON does not change, and Twine gives writers a visual graph where they can link passages intuitively. Macros handle transitions, inventory and branching. The video frames this as a division of labor: writers own the flow, developers own the logic.

The Unity starter kit

The Unity kit is described in six steps:

  1. Load the narrative JSON into game objects.
  2. Build the dialogue UI panels, with typewriter text and choice buttons.
  3. Implement branching logic so a choice leads to a scene and an emotion update.
  4. Layer AI-generated responses around the scaffold.
  5. Add audio and visual feedback, such as voice, portraits and transitions.
  6. Build and test, playtesting every branch and validating the emotional arcs.

The same approach works for 2D or 3D projects, since it is one JSON with many front ends.

Why templates pay off

The video presents templates and frameworks as the hidden scaffolding behind generative storytelling. They let you prototype fast, test cheaply and scale with confidence. The closing point is that a template spares you setup code so you can spend your energy on emotional nuance.

Key takeaways

  • Do not start every narrative system from zero.
  • Model scenes as JSON nodes with text, choices, emotion modifiers and prompt context.
  • Keeping content out of code lets you swap scenes and localize dialogue without touching the engine.
  • A Python engine can load JSON, render scenes, update emotion and branch on choices.
  • Include fallback text for when the AI is unavailable.
  • Twine and Unity can consume the same JSON, so the data stays constant while the presentation changes.
  • Writers can own flow in Twine while developers own logic.

Try it yourself

Take one scene from your own game and write it as a JSON node with its text, two choices and one emotion modifier. The video calls that your first reusable block, and suggests building a second one the next day.

Full transcript(auto-generated, with timestamps)

[0:00]Generative AI for game development, templates and frameworks, reusable building blocks for AI stories. Chapter 24, templates and frameworks. The big idea, stop building every narrative system from zero. Create reusable building blocks, templates, and frameworks you can adapt to any genre, mood, or storytelling style. Build once, reuse forever. Three core areas, Python and JSON templates for branching logic and emotion-aware dialogue, Twine structures for modular interactive fiction, and Unity starter kits for narrative-driven 2D or 3D experiences, each with framework code and customization guidance. Template one, the JSON narrative schema. Scenes become nodes, each with text, choices, emotion modifiers, and AI prompt context and dynamic variables. Content separated

[0:48]From code, swap scenes, localize dialogue, scale to hundreds of nodes without touching the engine. The architecture, JSON nodes feed the Python engine, which renders scenes, tracks emotional state, and branches on player choice. Data tells the story, code runs the machine. Change the JSON, change the game, no recompile. Template two, the Python story engine. Modular, readable, extensible. Load the JSON, render the current scene, update the emotional state, present choices, follow the branch. The engine reads, the data tells. One engine, infinite stories. The case study, a sci-fi mystery. You're a deep space engineer receiving fragmented messages from a vanished crew. Your interpretations shape plot outcomes and emotional tone, and there's always

[1:32]Fallback text, graceful degradation when the AI is unavailable. Twine, the visual front end. Each passage maps to a story node. Using Harlow or SugarCube with JavaScript, you load the same JSON at runtime, track player state and emotions across passages, and build branching paths that mirror your Python engine visually. The integration, same data, new presentation. The JSON nodes don't change. Twine provides the visual graph where writers link passages intuitively. Macros handle transitions, inventory, and branching. Writers own the flow, developers own the logic. True collaboration. Unity starter kit steps 1 through 4. 1. Load the narrative JSON into game objects. 2. Build the dialogue UI panels, typewriter text, choice buttons.

[2:17]3. Implement branching logic, choice leads to scene emotion updates. 4. Layer AI-generated responses around the scaffold. Steps 5 and 6. 5. Add audio and visual feedback, voice, portraits, transitions. 6. Build and test, playtest every branch, validate the emotional arcs, then scale 2D or 3D, same data, new presentation. One JSON, many front ends. Templates and frameworks are the hidden scaffolding behind generative storytelling. They let you prototype fast, test cheap, and scale with confidence. Narrative intent plus technical structure, flexible yet purposeful, ready to evolve across platforms. The takeaway, don't start from zero. Build reusable blocks, Python and JSON for logic, Twine for flow, Unity for scale. Spend your energy on emotional

[3:04]Nuance, not setup code. That's what templates buy you. Your turn, take one scene from your game and write it as a JSON node text, two choices, one emotion modifier. That's your first reusable block. Build the second one tomorrow. That's chapter 24. Next, the final chapter, real-world applications. If this helped, subscribe and I'll see you in video 25.

More from Generative AI for Game Development — Shesh Narayan Gupta

Humanitarians AI Lyrical Literacy Project