Skip to content

Migrating from LeoEcsLite ​

A practical guide for teams moving code from LeoEcsLite to KenseiECS. Both are sparse-set frameworks with int entity indices in filters, pools per component type, and Init/Run/Destroy systems, so most code maps line by line. This document lists the mapping, then the places where behavior differs, then a worked migration of a typical system.

The LeoEcsLite side describes the core package (Leopotam.EcsLite). Where a feature comes from an extension package (ecslite-extendedsystems, ecslite-di, ecslite-threads, ecslite-unityeditor) it is called out.

Side-by-side mapping ​

World and entities ​

ConcernLeoEcsLiteKenseiECS
Create a worldvar world = new EcsWorld(); / new EcsWorld(in EcsWorld.Config)var world = new World(); / new World(new WorldConfig { ... })
Tear downworld.Destroy();world.Destroy(); (also world.Clear() to reset without freeing)
Create an entityint e = world.NewEntity(); then pool.Add(e)Entity e = world.CreateEntity(new Position());
Destroy an entityworld.DelEntity(e);world.DestroyEntity(e);
Copy an entityworld.CopyEntity(src, dst); onto an existing dstEntity copy = world.CopyEntity(src); creates the copy
Alive checkpacked.Unpack(world, out int e)world.IsAlive(entity)
Entity handle for storageEcsPackedEntity p = world.PackEntity(e);Entity h = world.GetEntity(e);
Handle with worldEcsPackedEntityWithWorld / world.PackEntityWithWorld(e)none; store the World reference alongside the Entity
Generationworld.GetEntityGen(e) (short)entity.Generation (int)
Component countworld.GetComponentsCount(e)world.GetComponentCount(entity)
Component types on an entityworld.GetComponentTypes(e, ref Type[] list)world.GetComponentTypes(entity, List<int> result) then ComponentType.TypeOf(index)
Entity countworld.GetEntitiesCount()world.EntityCount
Index to handle, safe for any intnoneworld.TryGetEntity(index, out Entity entity)
Save / loadnone in coreWorldSerializer.Save(world, stream) / Load(world, stream); IComponentFormatter<T> for components with references

Pools and components ​

ConcernLeoEcsLiteKenseiECS
Component declarationstruct Health { public float Value; }struct Health : IComponent { public float Value; }
Get a poolEcsPool<Health> pool = world.GetPool<Health>();ComponentPool<Health> pool = world.Pool<Health>();
Addref var hp = ref pool.Add(e); hp.Value = 100;ref var hp = ref world.Add(e, new Health { Value = 100 }); or pool.Add(e.Index, value)
Getref var hp = ref pool.Get(e);ref var hp = ref world.Get<Health>(e); or pool.Get(e.Index)
Haspool.Has(e)world.Has<Health>(e) or pool.Has(e.Index)
Removepool.Del(e);world.Remove<Health>(e); or pool.Remove(e.Index)
Copy one componentpool.Copy(src, dst);none per pool; world.CopyEntity copies all
Raw arrayspool.GetRawDenseItems(), GetRawSparseItems()pool.RawData, pool.RawEntities, pool.Count
Type idpool.GetId(), world.GetPoolById(id), world.GetPoolByType(type)ComponentType<T>.Index, pool.TypeIndex, world.GetPool(typeIndex)
Reset hookIEcsAutoReset<T>.AutoReset(ref T c), called on Add and on DelIAutoReset<T>.AutoReset(ref T c), called on Remove (and by Warmup/Clear) only
Copy hookIEcsAutoCopy<T>.AutoCopy(ref T src, ref T dst), replaces the default copyIAutoCopy<T>.AutoCopy(ref T c), runs on a shallow copy already made
Pool eventsnoneIComponentListener<T> via pool.AddListener
Change trackingnonepool.TrackChanges(), pool.Modify(e), pool.MarkChanged(e), pool.ChangedSince(e, version), world.ChangeVersion

Filters ​

ConcernLeoEcsLiteKenseiECS
Buildworld.Filter<Position>().Inc<Velocity>().Exc<Frozen>().End()world.Filter().Inc<Position>().Inc<Velocity>().Exc<Frozen>().End()
Static formnoneworld.Filter<Inc<Position, Velocity>, Exc<Frozen>>()
Any-ofnone.Any<Health>().Any<Shield>() or Any<Health, Shield> spec
Iterateforeach (int e in filter)foreach (int e in filter)
Countfilter.GetEntitiesCount()filter.Count, filter.IsEmpty
Raw entitiesfilter.GetRawEntities()filter.Entities (ReadOnlySpan<int>)
Membership testfilter.GetSparseIndex()[e] > 0filter.Contains(e)
One matchmanualfilter.First(), TryGetFirst, Single()
Enter/leave eventsLEOECSLITE_FILTER_EVENTS define + IEcsFilterEventListener via filter.AddEventListenerIFilterListener via filter.AddListener, always available
Identical constraintssame instancesame instance (dedup includes static specs and generated Init)
Aligned iteration without sparse lookupsnoneworld.Group<Position, Velocity>() with Data1/Data2/Entities spans

Systems ​

ConcernLeoEcsLiteKenseiECS
ContainerIEcsSystems systems = new EcsSystems(world, shared);var systems = new SystemsRunner(world, sharedData);
Registersystems.Add(new S());systems.Add(new S()); or systems.Add(new S(), "name")
Lifecyclesystems.Init(); systems.Run(); systems.Destroy();systems.Init(); systems.Run(); systems.Destroy();
Fluent initsystems.Add(...).Init();Add chains, Init() returns void; call it on its own line
Init systemIEcsInitSystem.Init(IEcsSystems systems)IInitSystem.Init(World world, SharedData shared)
Run systemIEcsRunSystem.Run(IEcsSystems systems)IRunSystem.Run(World world)
Destroy systemIEcsDestroySystem.Destroy(IEcsSystems systems)IDestroySystem.Destroy(World world)
Pre-init / post-destroyIEcsPreInitSystem, IEcsPostDestroySystemnone; order systems explicitly (Destroy runs in reverse registration order)
World inside a systemsystems.GetWorld()the World parameter
Shared dataone object: systems.GetShared<GameShared>()typed container: shared.Get<TimeService>(), shared.Get<SpawnConfig>("enemies"), shared.TryGet
Several worldssystems.AddWorld(w, "events"), systems.GetWorld("events")none; one World per runner, pass other worlds through SharedData
One-frame componentsmanual cleanup system, or DelHere<T>() from ecslite-extendedsystemssystems.OneFrame<T>() (end of Run) and systems.DelHere<T>() (positional), built in
Named / toggleable groupsAddGroup(...) from ecslite-extendedsystems, toggled by an EcsGroupSystemState eventAdd(system, "name"), SetActive("name", bool), IsActive("name"); a nested runner as a named group: AddGroup("name", runner)
Update vs FixedUpdatetwo independent EcsSystems instancesa phase: root.AddPhase("fixed", fixedRunner), root.GetRunner("fixed").Run()
Introspectionsystems.GetAllSystems()systems.SystemCount, systems.GetSystemInfo(i), systems.SetActive(i, bool)
Field injectionecslite-di: EcsPoolInject<T>, EcsFilterInject<Inc<A>, Exc<B>>, EcsSharedInject<T>, EcsWorldInject wrapper fields, filled by systems.Inject(...) at runtimesource generator: [Pool], [Inc]/[Exc]/[Any], [Group], [Shared] on fields of a partial system class; Init is generated at compile time
Threadsecslite-threadsnone
Warm-upnone; typically a system that spawns and destroys a crowd of entities at loadsystems.Warmup() (JIT and first-use paths), world.ReserveEntities(entities) and Pool<T>().Reserve(count) for the types whose count changes during play (entity storage, those pools and the filters over them, for the peak), EventBuffer<T>.Prewarm(lists, capacity) (event lists). Prewarm does not size the world: a warm-up that created entities needs those reserves as well
Unity entry pointa MonoBehaviour that creates EcsWorld and EcsSystems in Start, runs in Update, destroys in OnDestroysubclass EcsBootstrap, override Configure(update, fixedUpdate, lateUpdate, shared)
Inspector-authored entitiesecslite-unityeditor templates and monitoringEcsComponentProvider<T> subclasses next to an EcsEntityView, view.Spawn(world)

World events ​

LeoEcsLite (LEOECSLITE_WORLD_EVENTS define)KenseiECS (always on)
IEcsWorldEventListener.OnEntityCreated(int entity)IWorldEventListener.OnEntityCreated(int entityIndex)
OnEntityChanged(int entity)OnComponentAdded(int entityIndex, int typeIndex) and OnComponentRemoved(int entityIndex, int typeIndex)
OnEntityDestroyed(int entity)OnEntityDestroyed(int entityIndex)
OnFilterCreated, OnWorldResized, OnWorldDestroyednone (world.FilterCount/GetFilter(i) and world.IsDestroyed cover the tooling cases)
world.AddEventListener(listener)world.AddEventListener(listener) / RemoveEventListener

Things KenseiECS has that Lite core does not ​

CommandBuffer with PendingEntity, GetSingleton<T>()/GetSingletonEntity<T>()/HasSingleton<T>(), EventBuffer<T> with world.AddEvent, Listeners<T> with Subscribe/Unsubscribe, IComponentListener<T>, Any filters, static filter specs, owning groups (world.Group<T1, T2>()), change tracking (TrackChanges/Modify/ChangedSince), snapshots (WorldSerializer), the source generator for Init, EcsBootstrap, EcsComponentProvider<T> with EcsEntityView.Spawn, the Systems window, and the World Inspector and Profiler windows under KENSEI_DEBUG, plus per-system Unity ProfilerMarkers.

Things Lite has that KenseiECS does not ​

EcsPackedEntityWithWorld, named multi-world support inside one systems group, IEcsPreInitSystem/IEcsPostDestroySystem, pool.Copy(src, dst) for a single component, EcsWorld.Config.RecycledEntities/PoolRecycledSize tuning, runtime injection of arbitrary instances by type (ecslite-di's EcsCustomInject<T> / systems.Inject(instance); KenseiECS routes those through SharedData and [Shared]), the threading extension, and the broader third-party ecosystem.

Behavior differences ​

An entity must be created with a component ​

Lite lets NewEntity() return an empty entity that you populate afterwards; an entity with no components is a leak Lite's DEBUG build reports later. KenseiECS has no empty state: CreateEntity<T>(T) allocates the slot and adds the first component in one call, and world listeners see OnEntityCreated only after that component is in place.

csharp
// LeoEcsLite
int e = world.NewEntity();
ref var pos = ref positions.Add(e);
pos.X = 10f;
velocities.Add(e);
csharp
// KenseiECS
Entity e = world.CreateEntity(new Position { X = 10f });
world.Add(e, new Velocity());

Auto-destroy on last component removal ​

Same rule in both frameworks: removing the last component destroys the entity. Two consequences in KenseiECS worth knowing:

  • OneFrame<T> / DelHere<T> cleanup auto-destroys entities whose only component was the one-frame component, so "event entities" need no cleanup code.
  • world.Unsubscribe<T> keeps the (empty) Listeners<T> component so that unsubscribing the last listener does not destroy the entity.

No lock counter on iteration ​

Lite's EcsFilter.Enumerator locks the filter; membership changes made during the loop are queued and applied when the outermost foreach ends. The dense array does not change under the loop, so a not-yet-visited entity that you destroyed is still yielded later in the same loop (and its components are then gone), while a newly matching entity is not visited.

KenseiECS applies changes immediately and iterates in reverse over a swap-removed array:

  • Safe inside foreach: destroying the current entity, adding/removing components on the current entity, creating entities. New matches are not visited in the current loop, as in Lite. A destroyed entity is never yielded afterwards.
  • Not safe: destroying or removing a required component from a not-yet-visited entity of the filter being iterated. The swap-remove can move an already visited entity below the cursor and visit it twice. Under KENSEI_DEBUG this throws at the moment it would happen. Defer such changes with a CommandBuffer.
csharp
// LeoEcsLite: allowed, applied after the loop
foreach (int e in _projectiles) {
    foreach (int t in _targets) {
        if (Hits(e, t)) {
            _world.DelEntity(e);
            if (_damage.Has(t)) {
                _damage.Get(t).Value += 10;   // a second projectile on this target this frame
            } else {
                _damage.Add(t).Value = 10;
            }
            break;
        }
    }
}
csharp
// KenseiECS: record, then play back
foreach (int e in _projectiles) {
    foreach (int t in _targets) {
        if (Hits(e, t)) {
            _buffer.DestroyEntity(world.GetEntity(e));
            // every projectile that hits this target in the frame adds its own Hit
            world.AddEvent(world.GetEntity(t), new Hit { Damage = 10 });
            break;
        }
    }
}
_buffer.Playback(world);

Keep one CommandBuffer per system; it allocates nothing after the first frame. Two projectiles can hit one target in a frame, so the hits are not a component written once: the Lite side adds the damage up by hand, and the KenseiECS side appends each hit to the target's EventBuffer<Hit> with world.AddEvent (register OneFrame<EventBuffer<Hit>>() on the runner).

Remove of a missing component is a no-op, Add of a duplicate throws ​

Remove<T> on an entity without T does nothing and does not create the pool, like Lite's Del. Add<T> on an entity that already has T throws InvalidOperationException in every build, where Lite checks only under DEBUG. Use Get to overwrite an existing component, or CommandBuffer.Set for add-or-overwrite.

Add takes a value ​

Lite's pool.Add(e) returns a ref to a fresh component that you then fill (or that IEcsAutoReset initialized). KenseiECS's Add(entity, value) stores the value you pass and returns a ref to it. Initialization moves into the argument:

csharp
// LeoEcsLite
ref var hp = ref healths.Add(e);
hp.Value = 100;
csharp
// KenseiECS
world.Add(e, new Health { Value = 100 });

AutoReset runs on remove only ​

Lite calls IEcsAutoReset<T>.AutoReset both for new components on Add and for removed ones on Del, so code often allocates lists there and relies on Add returning a ready component. KenseiECS calls IAutoReset<T>.AutoReset for the removed component only (plus Warmup and Clear, so it must accept default(T)), and the moved component after a swap-remove is untouched. Components without the interface are reset to default(T). Move allocation to the Add call site:

csharp
// LeoEcsLite
struct Inventory : IEcsAutoReset<Inventory> {
    public List<int> Items;
    public void AutoReset(ref Inventory c) {
        c.Items ??= new List<int>();
        c.Items.Clear();
    }
}

void Spawn(int e) {
    ref var inv = ref inventories.Add(e);   // Items is ready
}
csharp
// KenseiECS
struct Inventory : IComponent, IAutoReset<Inventory> {
    public List<int> Items;
    public void AutoReset(ref Inventory c) {
        c.Items?.Clear();
        c.Items = null;
    }
}

void Spawn(Entity e) {
    world.Add(e, new Inventory { Items = new List<int>() });
}

AutoCopy signature ​

Lite's AutoCopy(ref T src, ref T dst) replaces the default copy entirely. KenseiECS makes a shallow copy first and hands it to AutoCopy(ref T c) for deep-copying reference fields; value fields are already copied.

Generation semantics ​

Lite stores a 16-bit generation per slot and invalidates it when the entity is deleted. KenseiECS stores a 32-bit generation that changes when the slot is reused, not when it is freed. world.GetEntity(index) on a dead slot therefore returns the same handle the entity had while alive (IsAlive is false for it), and a stored handle stays unequal to every future occupant of the slot. The practical rule is unchanged: keep Entity handles, never int indices, and check IsAlive before use.

csharp
// LeoEcsLite
struct Target { public EcsPackedEntity Entity; }

void Aim(ref Target target, int enemy) {
    target.Entity = world.PackEntity(enemy);
    // later
    if (target.Entity.Unpack(world, out int alive)) {
        ref var hp = ref healths.Get(alive);
    }
}
csharp
// KenseiECS
struct Target : IComponent { public Entity Entity; }

void Aim(ref Target target, int enemy) {
    target.Entity = world.GetEntity(enemy);
    // later
    if (world.IsAlive(target.Entity)) {
        ref var hp = ref world.Get<Health>(target.Entity);
    }
}

Entity is IEquatable<Entity> with ==/!=; Entity.Null is the "no entity" value.

Exception safety ​

KenseiECS documents what happens when user code throws inside the framework:

  • A world listener or AutoReset that throws during DestroyEntity still results in the slot being released; the exception propagates afterwards.
  • A system that throws in Run skips the remaining systems for that frame, but OneFrame cleanup still runs.
  • A system that throws in Init leaves the runner uninitialized after destroying, in reverse order, the systems whose Init completed before it (those that implement IDestroySystem); the next Init starts over.
  • A command that throws in CommandBuffer.Playback discards the remaining commands.

Do not assume the same in Lite; check its source for the paths you rely on.

Debug layer: KENSEI_DEBUG instead of DEBUG ​

Lite's sanity checks compile in DEBUG builds (in Unity, the editor and development builds). KenseiECS uses its own define, KENSEI_DEBUG, independent of the build configuration: toggle it from the Unity menu KenseiECS -> Debug Mode (it sets the define in the active Build Profile on Unity 6 or, without one, in the Player Settings of the active build target only), or add it to DefineConstants in a .NET project. Without the define no validation code exists in the assembly. What each configuration checks is tabulated in Release vs. KENSEI_DEBUG.

Filters need an Inc or Any ​

Both frameworks reject exclude-only filters (Lite by requiring a type argument on Filter<T>(), KenseiECS by throwing from End()). KenseiECS additionally rejects a type in both Inc and Exc, or in both Any and Exc.

ref validity ​

In both, a ref T from Get/Add points into the pool's dense array, not at the entity, but KenseiECS invalidates it in more cases. Lite's pool recycles freed dense slots (_recycledItems) instead of moving the last component into them, so there a ref survives another entity's Del of the same type; here it does not. In KenseiECS a ref from Get/Add/Modify is invalidated by:

  • an Add of the same component type to any entity: the dense array may grow and move;
  • a Remove of the same component type from any entity, not only from this one: swap-remove moves the last component into the freed slot. That includes the removals inside DestroyEntity, auto-destroy after the last component, OneFrame and DelHere cleanup, CommandBuffer.Playback and World.Clear;
  • in a pool that belongs to an owning group: an Add or Remove of any of the group's types, which reorders the dense arrays of all its pools;
  • pool.Reserve (or the obsolete world.Reserve(entities, components)) when it grows the pool's dense arrays, and World.Destroy.

Listeners run inside Add, Remove and DestroyEntity, so a call that triggers them may do any of these. An Add/Remove of a different type that is not grouped with this one, Get, Has and filter iteration leave the ref valid. Re-acquire after structural changes, in particular a ref kept across a loop that removes or destroys other entities with the same component; Add itself returns a ref to a scratch value if a listener removed the component or destroyed the entity before it returned.

Destroy order of systems ​

KenseiECS runs IDestroySystem.Destroy in reverse registration order and makes the runner re-initializable afterwards. If your Lite code depends on a particular destroy order, verify it against Lite's implementation before relying on either.

Groups: aligned iteration (no Lite equivalent) ​

Lite iterates a filter and reads each component through the pool's sparse array. KenseiECS has the same path, plus owning groups: world.Group<Position, Velocity>() keeps the two pools' dense arrays aligned so members sit at the same index in each, packed at the front, and exposes them as spans.

csharp
// LeoEcsLite
foreach (int e in _moving) {
    ref var pos = ref _positions.Get(e);
    ref var vel = ref _velocities.Get(e);
    pos.X += vel.X;
}
csharp
// KenseiECS, with a group
var pos = _group.Data1;
var vel = _group.Data2;
for (int i = 0; i < pos.Length; i++) {
    pos[i].X += vel[i].X;
}

A component type can be owned by one group only; filters over the same types keep working. Groups are for the few hottest loops, not a replacement for filters. Iterate downward when destroying members inside the loop.

Change tracking (no Lite equivalent) ​

Lite has no notion of "changed since". KenseiECS tracks per pool after TrackChanges(): Modify(e) and MarkChanged(e) stamp a component with a world-wide version, ChangedSince(e, version) compares against a bookmark taken from world.ChangeVersion. Get does not mark, so code ported from Lite that writes through Get must switch to Modify where a consumer relies on the flag.

Snapshots (no Lite equivalent) ​

Lite core has no save/load. WorldSerializer.Save(world, stream) writes every alive entity and component; Load(world, stream) restores them into an empty world with the same indices and generations, so Entity fields inside components stay valid. Unmanaged components are written bit-for-bit; a component with reference fields needs an IComponentFormatter<T> registered on the serializer.

Generated Init instead of ecslite-di ​

ecslite-di fills wrapper fields by reflection when systems.Inject(...) runs. KenseiECS ships a Roslyn source generator that writes Init at compile time from attributes on plain fields. The class must be partial; custom setup goes into partial void OnInit.

csharp
// LeoEcsLite + ecslite-di
public sealed class MovementSystem : IEcsRunSystem {
    private readonly EcsFilterInject<Inc<Position, Velocity>, Exc<Frozen>> _moving = default;
    private readonly EcsPoolInject<Position> _positions = default;
    private readonly EcsPoolInject<Velocity> _velocities = default;
    private readonly EcsSharedInject<GameShared> _shared = default;

    public void Run(IEcsSystems systems) {
        foreach (int e in _moving.Value) {
            ref Position pos = ref _positions.Value.Get(e);
            ref Velocity vel = ref _velocities.Value.Get(e);
            pos.X += vel.X * _shared.Value.DeltaTime;
        }
    }
}
// bootstrap: systems.Inject().Init();
csharp
// KenseiECS + generator
public sealed partial class MovementSystem : IRunSystem {
    [Inc(typeof(Position), typeof(Velocity))] [Exc(typeof(Frozen))]
    private Filter _moving;
    [Pool] private ComponentPool<Position> _positions;
    [Pool] private ComponentPool<Velocity> _velocities;
    [Shared] private GameShared _shared;

    public void Run(World world) {
        foreach (int e in _moving) {
            ref Position pos = ref _positions.Get(e);
            ref Velocity vel = ref _velocities.Get(e);
            pos.X += vel.X * _shared.DeltaTime;
        }
    }
}
// bootstrap: nothing extra; the generated Init runs in systems.Init()

Differences: the fields are the real Filter/ComponentPool<T> types, not wrappers with .Value; there is no runtime Inject step and no reflection; there is no EcsWorldInject because World is a parameter of Run; keyed shared data is [Shared("key")]. The generator DLL sits in Plugins/ with the RoslynAnalyzer label and is picked up by Unity 2021.2+; a .NET project references the generator as an analyzer. Misuse is a compile error (KECS001 to KECS012, KECS017 to KECS019) or a compiler warning (KECS013 for a hand-written override of a generated Init without base.Init, KECS014 to KECS016 for a marked field that is not injected), not a runtime failure; the table is in Generated Init.

EcsBootstrap as the Unity entry point ​

Lite's README shows a MonoBehaviour that creates the world and systems in Start and runs them in Update. KenseiECS provides that class:

csharp
// LeoEcsLite
public sealed class Startup : MonoBehaviour {
    private EcsWorld _world;
    private IEcsSystems _systems;

    private void Start() {
        _world = new EcsWorld();
        _systems = new EcsSystems(_world, new GameShared());
        _systems
            .Add(new MovementSystem())
            .Init();
    }

    private void Update() {
        _systems?.Run();
    }

    private void OnDestroy() {
        _systems?.Destroy();
        _world?.Destroy();
    }
}
csharp
// KenseiECS
public sealed class GameBootstrap : EcsBootstrap {
    protected override void Configure(SystemsRunner update, SystemsRunner fixedUpdate, SystemsRunner lateUpdate, SharedData shared) {
        shared.Add(new GameShared());
        update.Add(new MovementSystem());
        fixedUpdate.Add(new PhysicsSystem());
        lateUpdate.Add(new SyncTransformSystem());
    }
}

EcsBootstrap creates the World, the SharedData and three runners in Awake (so other scripts can use World and Shared from their Start), calls Warmup or Init in Start, drives the runners from Update/FixedUpdate/LateUpdate, and destroys systems then world in OnDestroy. Two EcsSystems instances for Update and FixedUpdate become the update and fixedUpdate runners of one bootstrap. The editor windows find it through IEcsWorldProvider/IEcsSystemsProvider.

Step-by-step migration ​

  1. Install the package (Unity: git URL with ?path=/KenseiECS; .NET: reference KenseiECS.NET/KenseiECS.csproj). Replace using Leopotam.EcsLite; with using KenseiECS;.
  2. Mark components with IComponent. Convert IEcsAutoReset<T> to IAutoReset<T> and move any allocation it did on add to the Add call sites. Convert IEcsAutoCopy<T> to IAutoCopy<T> with the single-argument signature.
  3. Bootstrap: EcsWorld -> World; EcsSystems -> SystemsRunner; wrap your shared object in a SharedData container. In Unity, subclass EcsBootstrap instead of writing the MonoBehaviour yourself.
  4. Systems: change interfaces and signatures. Replace systems.GetWorld() with the World parameter and systems.GetShared<T>() with shared.Get<T>() in Init. Cache pools and filters in Init as before, or make the class partial, mark the fields with [Inc]/[Exc]/[Any]/[Pool]/[Group]/[Shared] and delete Init; the generator writes it. ecslite-di wrapper fields map one to one.
  5. Entity creation: replace NewEntity() + first Add with CreateEntity(firstComponent). Subsequent adds become world.Add(entity, value).
  6. Stored references: EcsPackedEntity -> Entity, PackEntity -> GetEntity, Unpack -> IsAlive.
  7. Filters: Filter<A>().Inc<B>() -> Filter().Inc<A>().Inc<B>() or Filter<Inc<A, B>>().
  8. One-frame components: delete cleanup systems and register OneFrame<T>() or DelHere<T>() on the runner.
  9. Loops that modify other entities: route through a CommandBuffer.
  10. Enable KENSEI_DEBUG and run the game. The debug layer throws on stale handles, duplicate adds, unsafe removals during iteration and misuse of the runner, which surfaces most migration mistakes at their source.

Before: a LeoEcsLite system ​

csharp
using System.Collections.Generic;
using Leopotam.EcsLite;

public struct Position { public float X, Y; }
public struct Velocity { public float X, Y; }
public struct Frozen { }
public struct Expired { }

public sealed class GameShared {
    public float DeltaTime;
}

public sealed class MovementSystem : IEcsInitSystem, IEcsRunSystem {
    private EcsWorld _world;
    private EcsFilter _moving;
    private EcsPool<Position> _positions;
    private EcsPool<Velocity> _velocities;
    private EcsPool<Expired> _expired;
    private GameShared _shared;

    public void Init(IEcsSystems systems) {
        _world = systems.GetWorld();
        _moving = _world.Filter<Position>().Inc<Velocity>().Exc<Frozen>().End();
        _positions = _world.GetPool<Position>();
        _velocities = _world.GetPool<Velocity>();
        _expired = _world.GetPool<Expired>();
        _shared = systems.GetShared<GameShared>();
    }

    public void Run(IEcsSystems systems) {
        foreach (int e in _moving) {
            ref Position pos = ref _positions.Get(e);
            ref Velocity vel = ref _velocities.Get(e);
            pos.X += vel.X * _shared.DeltaTime;
            pos.Y += vel.Y * _shared.DeltaTime;
            if (pos.Y < 0f) {
                _expired.Add(e);
            }
        }
    }
}

public sealed class ExpiredCleanupSystem : IEcsRunSystem {
    public void Run(IEcsSystems systems) {
        EcsWorld world = systems.GetWorld();
        EcsFilter filter = world.Filter<Expired>().End();
        foreach (int e in filter) {
            world.DelEntity(e);
        }
    }
}

public sealed class Bootstrap {
    private EcsWorld _world;
    private IEcsSystems _systems;

    public void Start() {
        _world = new EcsWorld();
        _systems = new EcsSystems(_world, new GameShared { DeltaTime = 1f / 60f });
        _systems
            .Add(new MovementSystem())
            .Add(new ExpiredCleanupSystem())
            .Init();

        int e = _world.NewEntity();
        ref Position pos = ref _world.GetPool<Position>().Add(e);
        pos.X = 1f;
        ref Velocity vel = ref _world.GetPool<Velocity>().Add(e);
        vel.Y = -1f;
    }

    public void Update() {
        _systems.Run();
    }

    public void Stop() {
        _systems.Destroy();
        _world.Destroy();
    }
}

After: the same system in KenseiECS ​

csharp
using KenseiECS;

public struct Position : IComponent { public float X, Y; }
public struct Velocity : IComponent { public float X, Y; }
public struct Frozen : IComponent { }
public struct Expired : IComponent { }

public sealed class GameShared {
    public float DeltaTime;
}

public sealed class MovementSystem : IInitSystem, IRunSystem {
    private Filter _moving;
    private ComponentPool<Position> _positions;
    private ComponentPool<Velocity> _velocities;
    private GameShared _shared;

    public void Init(World world, SharedData shared) {
        _moving = world.Filter<Inc<Position, Velocity>, Exc<Frozen>>();
        _positions = world.Pool<Position>();
        _velocities = world.Pool<Velocity>();
        _shared = shared.Get<GameShared>();
    }

    public void Run(World world) {
        foreach (int e in _moving) {
            ref Position pos = ref _positions.Get(e);
            ref Velocity vel = ref _velocities.Get(e);
            pos.X += vel.X * _shared.DeltaTime;
            pos.Y += vel.Y * _shared.DeltaTime;
            if (pos.Y < 0f) {
                world.Add(world.GetEntity(e), new Expired());
            }
        }
    }
}

public sealed class ExpiredCleanupSystem : IInitSystem, IRunSystem {
    private Filter _expired;

    public void Init(World world, SharedData shared) {
        _expired = world.Filter<Inc<Expired>>();
    }

    public void Run(World world) {
        foreach (int e in _expired) {
            world.DestroyEntity(world.GetEntity(e));
        }
    }
}

public sealed class Bootstrap {
    private World _world;
    private SystemsRunner _systems;

    public void Start() {
        _world = new World();
        var shared = new SharedData();
        shared.Add(new GameShared { DeltaTime = 1f / 60f });

        _systems = new SystemsRunner(_world, shared)
            .Add(new MovementSystem())
            .Add(new ExpiredCleanupSystem());
        _systems.Init();

        Entity e = _world.CreateEntity(new Position { X = 1f });
        _world.Add(e, new Velocity { Y = -1f });
    }

    public void Update() {
        _systems.Run();
    }

    public void Stop() {
        _systems.Destroy();
        _world.Destroy();
    }
}

Points to notice in the diff:

  • Add on the current entity inside the loop is fine in both frameworks; adding Expired does not touch the _moving filter's membership.
  • ExpiredCleanupSystem destroys the current entity of the filter it iterates, which is safe. The filter is built once in Init because End() allocates and scans the registry; Lite tolerated building it per frame.
  • If Expired were the only component of some entity, KenseiECS's DelHere<Expired>() would replace the whole cleanup system: removing the last component destroys the entity.
  • Init() is not chainable on SystemsRunner; Add returns the runner, Init returns void.

After, with the generator ​

The same MovementSystem without a hand-written Init:

csharp
public sealed partial class MovementSystem : IRunSystem {
    [Inc(typeof(Position), typeof(Velocity))] [Exc(typeof(Frozen))]
    private Filter _moving;
    [Pool] private ComponentPool<Position> _positions;
    [Pool] private ComponentPool<Velocity> _velocities;
    [Shared] private GameShared _shared;

    public void Run(World world) {
        foreach (int e in _moving) {
            ref Position pos = ref _positions.Get(e);
            ref Velocity vel = ref _velocities.Get(e);
            pos.X += vel.X * _shared.DeltaTime;
            pos.Y += vel.Y * _shared.DeltaTime;
            if (pos.Y < 0f) {
                world.Add(world.GetEntity(e), new Expired());
            }
        }
    }
}

The generated part adds IInitSystem and an Init that builds the filter, fetches the pools and reads the shared object, then calls partial void OnInit(World world, SharedData shared) if you implement it. The bootstrap is unchanged.