unity-ecs-patterns
Implement Unity ECS Patterns
Building high-performance Unity games requires specialized data-oriented patterns that traditional OOP cannot provide. This skill provides production-ready ECS patterns using DOTS, Jobs, and Burst for games that scale to thousands of entities.
Download the skill ZIP
Upload in Claude
Go to Settings → Capabilities → Skills → Upload skill
Toggle on and start using
Test it
Using "unity-ecs-patterns". Create an ECS component for player health with current and max values, and a system that heals players over time.
Expected outcome:
- Component Definition:
- ```csharp
- public struct Health : IComponentData
- {
- public float Current;
- public float Max;
- }
- ```
- Healing System:
- ```csharp
- [BurstCompile]
- public partial struct HealthRegenSystem : ISystem
- {
- public void OnUpdate(ref SystemState state)
- {
- float deltaTime = SystemAPI.Time.DeltaTime;
- float regenRate = 5f;
- foreach (var health in
- SystemAPI.Query<RefRW<Health>>())
- {
- health.ValueRW.Current = math.min(
- health.ValueRO.Max,
- health.ValueRO.Current + regenRate * deltaTime
- );
- }
- }
- }
- ```
Using "unity-ecs-patterns". How do I convert a GameObject to an entity with authoring?
Expected outcome:
- 1. Create an Authoring MonoBehaviour:
- ```csharp
- public class EnemyAuthoring : MonoBehaviour
- {
- public float Speed;
- public float Health;
- class Baker : Baker<EnemyAuthoring>
- {
- public override void Bake(EnemyAuthoring authoring)
- {
- var entity = GetEntity(TransformUsageFlags.Dynamic);
- AddComponent(entity, new Speed { Value = authoring.Speed });
- AddComponent(entity, new Health { Current = authoring.Health, Max = authoring.Health });
- }
- }
- }
- ```
- 2. Add the authoring component to a GameObject in the Editor
- 3. The baking system automatically converts it to an entity at build time
Using "unity-ecs-patterns". Write a parallel job that damages all enemies in a radius around each entity.
Expected outcome:
This requires a spatial hash approach. First, build a spatial hash map in a parallel job. Then run a second pass that queries nearby cells and applies damage. The spatial hash function uses prime number multiplication for uniform distribution: `hash = x * 73856093 ^ y * 19349663 ^ z * 83492791`.
Security Audit
SafeAll 59 static findings are false positives. The skill contains Unity ECS documentation with code examples. Detected patterns (hash functions, system API references, backticks) are legitimate game development patterns and Markdown formatting, not security threats.
Quality Score
What You Can Build
Indie Game Developer Building Performance-Critical Games
Create efficient game systems that handle thousands of enemies, particles, or units without performance degradation using ECS patterns.
Gameplay Programmer Learning DOTS
Transition from traditional Unity MonoBehaviour patterns to data-oriented ECS architecture with guided examples and best practices.
Technical Artist Creating Particle Systems
Build massive particle and effect systems that process in parallel using Jobs and Burst compilation for GPU-like performance on CPU.
Try These Prompts
Create a Speed component and a MovementSystem in Unity ECS using ISystem and BurstCompile. The system should move entities forward based on their speed value.
Write a SpawnSystem that uses EntityCommandBuffer to create entities at runtime with a Spawner component. Include both single-threaded and parallel job versions.
Create a CharacterAspect that groups Health, Speed, and LocalTransform components. Include a method to apply damage that respects shield absorption logic.
Build a spatial hashing system using NativeParallelMultiHashMap for efficient collision queries. Include the hash function and parallel job for updating the spatial grid.
Best Practices
- Use ISystem instead of SystemBase for maximum performance and Burst compatibility
- Always apply [BurstCompile] to jobs and systems for optimal performance
- Defer structural changes (create/destroy/add) using EntityCommandBuffer to avoid breaking job scheduling
Avoid
- Avoid adding managed types (classes, strings, arrays) to components as they break Burst compilation
- Do not perform structural changes inside parallel jobs; use EntityCommandBuffer.ParallelWriter instead
- Avoid querying entities one-by-one; use entity queries and ToComponentDataArray for batch operations
Frequently Asked Questions
What Unity version supports ECS?
How is ECS different from MonoBehaviour?
Can I mix ECS with traditional GameObjects?
What is Burst and why should I use it?
How many entities can ECS handle?
Should I use Aspects or direct component access?
Developer Details
Author
wshobsonLicense
MIT
Repository
https://github.com/wshobson/agents/tree/main/plugins/game-development/skills/unity-ecs-patternsRef
main
File structure
📄 SKILL.md