Skip to content

Interface IAutoReset<T> ​

Namespace: KenseiECS

Implement on a component struct to provide custom reset logic when the component is removed from an entity.

If not implemented, all fields are reset to default(T) automatically. Use this when you need to null out reference-type fields or set specific default values.

Usage:

csharp
struct InventoryComponent : IComponent, IAutoReset<InventoryComponent> {
    public List<int> Items;
    public void AutoReset(ref InventoryComponent c) {
        c.Items?.Clear();
        c.Items = null;
    }
}
csharp
public interface IAutoReset<T> where T : struct

Type Parameters ​

T

Methods ​

AutoReset(ref T) ​

Reset component in place. Invoked on a default instance, so act on the parameter, not on this. It runs in the middle of a removal, before the pool and the world drop the component: reset the value only. Changing the world from here (adding or removing components, creating or destroying entities, subscribing listeners) is not supported.

csharp
void AutoReset(ref T component)

Parameters ​

component T