wrote a custom CLI tool to scaffold Godot scenes from templates, tired of copying boilerplate

27 views 0 replies

got tired of manually duplicating scene files every time I needed a new enemy, NPC, or interactable. the setup was always the same: create scene, attach script, wire up the animation player, add collision shapes, connect signals. so i wrote a small Python CLI that does it from a template.

the basic idea: you define a .template folder with a .tscn file, a .gd script, and a config.json that describes which placeholders to replace. then you run:

python3 scaffold.py enemy goblin --hp 30 --speed 120

and it spits out a goblin.tscn and goblin.gd in the right directory with all the placeholder values filled in. the config handles where files go, what naming convention to use, and which export vars get default values.

the template config looks like this:

{
  "scene_dir": "res://scenes/enemies/",
  "script_dir": "res://scripts/enemies/",
  "placeholders": {
    "__CLASS_NAME__": "{{name|pascal}}",
    "__HP__": "{{hp|default:50}}",
    "__SPEED__": "{{speed|default:100}}"
  }
}

it's nothing fancy, maybe 200 lines of Python. but it's saved me a surprising amount of time on a project with ~40 different enemy types that all share the same base structure but with different stats and animation sets.

one thing I'm still figuring out: how to handle templates that need different node trees. right now every enemy has the same node hierarchy, but some need extra raycasts or area2d triggers. considering adding optional node blocks to the template format but don't want to over-engineer it.

anyone else doing something like this? i know there are Godot editor plugins that do scene templating but i wanted something i could run from the terminal and integrate into my build scripts.