For AI agents: the complete documentation index is available at /AchEngine/en/llms.txt, the full documentation bundle is available at /AchEngine/en/llms-full.txt, and this page is available as Markdown at /AchEngine/en/usage/ecs/index.md.

ECS Wrapper

The ECS helpers connect Unity Entities with the AchEngine service and world abstractions. The module is optional and is compiled only when com.unity.entities is installed.

Basic usage

using AchEngine.ECS;
using Unity.Entities;

public partial struct DamageSystem : ISystem
{
    public void OnUpdate(ref SystemState state)
    {
        var ecb = state.World.GetOrCreateSystemManaged<EndSimulationEntityCommandBufferSystem>();
        // Query and update entities here.
    }
}

When should I use it?

Use the wrapper when gameplay data is already modeled as Entities and you need consistent world access, command buffers, bakers, or DI integration. Keep ordinary UI and scene orchestration in the regular AchEngine modules.

Use it from a system

public partial struct SpawnSystem : ISystem
{
    public void OnCreate(ref SystemState state) { }

    public void OnUpdate(ref SystemState state)
    {
        var world = state.World;
        var entityManager = world.EntityManager;
        // entityManager.CreateEntity(...);
    }
}

EntityManager extensions

The package provides convenience extensions for creating, querying, and retrieving components while keeping the standard EntityManager API available.

var entity = entityManager.CreateEntity(archetype);
entityManager.SetComponentData(entity, new Health { Value = 100 });

Use it from a Baker

public class UnitAuthoring : MonoBehaviour
{
    public int health = 100;
}

public class UnitBaker : Baker<UnitAuthoring>
{
    public override void Bake(UnitAuthoring authoring)
    {
        var entity = GetEntity(TransformUsageFlags.Dynamic);
        AddComponent(entity, new Health { Value = authoring.health });
    }
}

Inject an ECS world through DI

Register the desired world or an adapter in an installer and inject that abstraction into systems or services. This keeps world selection explicit in multi-world projects.

builder.RegisterInstance(World.Default);
builder.Register<IWorldService, WorldService>();