Skip to content

Recipes

Michael Yarichuk edited this page Oct 18, 2026 · 1 revision

Recipes

Query templates

repository.TryGetByName("goblin", out var t);        // O(1), case-insensitive
var melee = repository.GetByTags("enemy", "melee");  // ALL tags required
var all   = repository.GetByTags();                  // everything

On live entities: entity.HasTags("enemy"), parent.GetChildrenWithTags("enemy").

Spawn many

Inheritance is cached, dice and scripts are parsed once per distinct source, so spawning thousands of the same blueprint stays flat.

Save / load

There is no built-in save format. Persist the template name plus dynamic state, then re-spawn and re-apply:

// save
Save(templateName, entity.Get<Health>().Current, entity.Get<Position>());
// load
factory.TryCreate(savedTemplateName, out var e);
e.Set(new Health { Current = savedHp, Max = savedMax });

Mods and hot-reload

await repository.LoadTemplateFolderAsync("Mods/Extra", ct);

Loading is additive and atomic. There is no unload: to hot-reload, build a fresh EntityTemplateRepository + EntityFactory and drop the old pair. If you mutate a loaded template in place, call factory.InvalidateEffectiveTemplateCache().

Seeded, reproducible rolls

var rng = new Random(seed);
dice.Roll(rng);

Clone this wiki locally