Table of Contents

Class SystemBase

Namespace
KeenEyes
Assembly
KeenEyes.Abstractions.dll

Base class for ECS systems with common functionality.

public abstract class SystemBase : ISystem, IDisposable, ISystemLifecycle
Inheritance
SystemBase
Implements
Derived
Inherited Members

Examples

public class MovementSystem : SystemBase
{
    protected override void OnInitialize()
    {
        // Set up queries and resources
    }

    public override void Update(float deltaTime)
    {
        foreach (var entity in World.Query<Position, Velocity>())
        {
            ref var pos = ref World.Get<Position>(entity);
            ref readonly var vel = ref World.Get<Velocity>(entity);
            pos.X += vel.X * deltaTime;
            pos.Y += vel.Y * deltaTime;
        }
    }
}

Remarks

SystemBase provides a convenient implementation of ISystem with lifecycle hooks for initialization, enabling/disabling, and update phases.

Override OnInitialize() to set up queries and resources, OnBeforeUpdate(float) and OnAfterUpdate(float) for pre/post update logic, and Update(float) for the main processing logic.

The World property provides access to the IWorld interface. Systems that need access to concrete World features (like change tracking or events) can cast to the concrete World type in OnInitialize().

Properties

Enabled

Gets or sets whether this system is enabled. Disabled systems are skipped during world updates.

public bool Enabled { get; set; }

Property Value

bool

World

Gets the world this system operates on.

protected IWorld World { get; }

Property Value

IWorld

Remarks

This property returns the IWorld interface. Systems that need access to concrete World features (like change tracking, events, or hierarchy) can cast to the concrete World type in OnInitialize().

Exceptions

InvalidOperationException

Thrown when accessed before initialization.

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Dispose(bool)

Releases resources used by this system.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

True if called from Dispose(), false if called from finalizer.

Initialize(IWorld)

Called when the system is added to a world.

public virtual void Initialize(IWorld world)

Parameters

world IWorld

The world this system operates on.

InvokeAfterUpdate(float)

Invokes the OnAfterUpdate(float) lifecycle hook. Called by the world after the main update.

public void InvokeAfterUpdate(float deltaTime)

Parameters

deltaTime float

The time elapsed since the last update.

InvokeBeforeUpdate(float)

Invokes the OnBeforeUpdate(float) lifecycle hook. Called by the world before the main update.

public void InvokeBeforeUpdate(float deltaTime)

Parameters

deltaTime float

The time elapsed since the last update.

OnAfterUpdate(float)

Called after entity processing in Update(float). Override to perform post-update logic such as cleanup or statistics collection.

protected virtual void OnAfterUpdate(float deltaTime)

Parameters

deltaTime float

The time elapsed since the last update.

OnBeforeUpdate(float)

Called before entity processing in Update(float). Override to perform pre-update logic such as accumulating time or resetting state.

protected virtual void OnBeforeUpdate(float deltaTime)

Parameters

deltaTime float

The time elapsed since the last update.

OnDisabled()

Called when the system is disabled. Override to perform cleanup that should happen each time the system is deactivated.

protected virtual void OnDisabled()

OnEnabled()

Called when the system is enabled. Override to perform initialization that should happen each time the system is activated.

protected virtual void OnEnabled()

OnInitialize()

Called after the system is initialized with a world. Override to set up queries and resources.

protected virtual void OnInitialize()

Update(float)

Called each frame/tick to update the system.

public abstract void Update(float deltaTime)

Parameters

deltaTime float

Time elapsed since the last update in seconds.