Blueprint Components
Docs / Guides / Blueprint components
Use EntityBlueprint to create data-driven entity configurations with component snapshots, contexts, and binders.
Overview
EntityBlueprint is a ScriptableObject asset that stores:
- Component Snapshots: Serialized component data as JSON
- Context Assets: Shared and per-entity context configurations
- Binder Assets: View binding configurations
Blueprints enable data-driven entity spawning without code changes.
How It Works
Blueprint Structure
EntityBlueprint
├── Component Snapshot (EntityBlueprintData)
│ ├── Position { X: 0, Y: 0 }
│ ├── Velocity { X: 1, Y: 0 }
│ └── Health { Current: 100, Max: 100 }
├── Context Assets
│ ├── SharedContextAsset (UI Root)
│ └── PerEntityContextAsset (Audio Source)
└── Binder Assets
├── PositionBinderAsset
└── HealthBinderAsset
Spawning Process
- Create Entity: Via external command
- Apply Snapshot: Deserialize and attach components
- Register Contexts: Create and register contexts
- Create Binders: Instantiate and attach binders
Creating Blueprints
Step 1: Create Asset
- Project Window → Right-click
- Create → ZenECS → Entity Blueprint
- Name the asset (e.g., "PlayerBlueprint")
Step 2: Configure Components
In the Blueprint inspector:
- Expand Components (snapshot) section
- Click + to add component entries
- Select component type
- Configure component values
Supported Types:
- Primitive types (int, float, bool, string)
- Unity types (Vector2, Vector3, Color)
- Unity.Mathematics types (float2, float3, quaternion)
- Custom struct components
Step 3: Add Contexts (Optional)
- Expand Contexts (ScriptableObject assets) section
- Drag context assets into the list
- Configure shared or per-entity contexts
Step 4: Add Binders (Optional)
- Expand Binders (ScriptableObject assets) section
- Drag binder assets into the list
- Binders will be created when entity spawns
Usage
Spawning from Blueprint
using ZenECS.Adapter.Unity.Blueprints;
// Spawn entity
blueprint.Spawn(
KernelLocator.CurrentWorld,
ZenEcsUnityBridge.SharedContextResolver,
onCreated: entity => Debug.Log($"Spawned: {entity.Id}")
);
Spawning with EntityLink
// Spawn and link to GameObject
var world = KernelLocator.CurrentWorld;
blueprint.Spawn(world, sharedContextResolver, entity =>
{
var link = gameObject.AddComponent<EntityLink>();
link.Attach(world, entity);
});
Component Serialization
JSON Format
Components are serialized as JSON:
{
"type": "Position",
"data": {
"X": 0.0,
"Y": 0.0,
"Z": 0.0
}
}
Supported Types
Primitive Types:
int,float,double,bool,stringbyte,short,long,uint,ushort,ulong
Unity Types:
Vector2,Vector3,Vector4Color,QuaternionRect,Bounds
Unity.Mathematics:
float2,float3,float4int2,int3,int4quaternion
Custom Structs:
- Any
structwith public fields - Nested structs supported
Examples
Basic Blueprint
PlayerBlueprint asset:
- Components:
Position,Velocity,Health - Contexts: None
- Binders:
PositionBinderAsset
Usage:
playerBlueprint.Spawn(world, sharedContextResolver);
Complex Blueprint
EnemyBlueprint asset:
- Components:
Position,Velocity,Health,AIState - Contexts:
EnemyAudioContext(per-entity) - Binders:
PositionBinderAsset,HealthBarBinderAsset
Usage:
enemyBlueprint.Spawn(world, sharedContextResolver, entity =>
{
// Additional setup after spawning
world.Publish(new EnemySpawnedMessage { Entity = entity });
});
Best Practices
✅ Do
- Use blueprints for common entities: Players, enemies, items
- Organize by type: Group related blueprints in folders
- Test in editor: Verify blueprints before runtime
- Version snapshots: Keep backup of blueprint data
❌ Don't
- Don't store references: Blueprints are data, not code
- Don't over-complicate: Keep blueprints focused
- Don't duplicate: Reuse blueprints with variations
Advanced Patterns
Blueprint Inheritance
Create base blueprints and extend:
// Base blueprint: Common components
var baseBlueprint = CreateAsset<EntityBlueprint>("BaseEntity");
baseBlueprint.Data.AddComponent(new Position(0, 0));
baseBlueprint.Data.AddComponent(new Health(100, 100));
// Extended blueprint: Add specific components
var enemyBlueprint = CreateAsset<EntityBlueprint>("Enemy");
enemyBlueprint.Data = baseBlueprint.Data.Clone();
enemyBlueprint.Data.AddComponent(new AIState());
Runtime Blueprint Creation
Create blueprints at runtime:
var blueprint = ScriptableObject.CreateInstance<EntityBlueprint>();
blueprint.Data.AddComponent(new Position(0, 0));
blueprint.Data.AddComponent(new Velocity(1, 0));
// Spawn immediately
blueprint.Spawn(world, sharedContextResolver);
Troubleshooting
Components Not Serializing
Issue: Component not appearing in snapshot
Solutions:
- Check component is a
struct - Verify public fields exist
- Check type is supported
- Review serialization format
Blueprint Spawn Fails
Issue: Entity not created
Solutions:
- Verify world is active
- Check shared context resolver is configured
- Review component types are valid
- Check for serialization errors
See Also
- Entity Blueprint API - API reference
- View Binder - Binder system
- Binding System - Core binding concepts