Skip to content

Spawning Entities

Neofox: thumbsup Bringing Entities to Life

Every entity starts here! Spawning is how you create new entities in your World, ready to receive components and participate in your game.

The World.Spawn() method is the simplest way to create a new entity. It returns the entity immediately, and you can chain Add calls to attach components.

cs
var world = new World();

// Spawn a single entity
var entity = world.Spawn()
    .Add(new Position { X = 0, Y = 0 })
    .Add<Velocity>(); // velocity has new(), so default value is used

In this example, we create a new entity using World.Spawn() and add two components (Position and Velocity) to it using the Add method. The entity is automatically spawned in the world after the components are added.

The handle you get back is a plain Entity value — store it in variables, collections, or even as a component on another entity. It stays valid until the entity despawns, and it always knows whether it's still alive.

Neofox: think Paws for Thought: Archetype Churning

Each Add call moves the entity to a new archetype. For simple entities, this is fine! But for complex entities with many components — or when spawning whole waves — reach for the EntityTemplate instead, which spawns entities directly into their final archetype.

Quick Reference

ScenarioRecommended
Single entity, few componentsWorld.Spawn()
Prototyping/debuggingWorld.Spawn()
Single entity, many componentsEntityTemplate
Bulk spawning (10+ entities)EntityTemplate
Entity templates/factoriesEntityTemplate

Neofox: science Need a Wave, not a Fox?

Templates covers the EntityTemplate: reusable templates, spawning 100,000 entities in one call, and getting all their handles delivered straight into your Span<Entity>.