Skip to content

Interface IAutoCopy<T> ​

Namespace: KenseiECS

Implement on a component struct to provide custom copy logic when the component is copied via World.CopyEntity().

Called on a shallow copy of the source component. Use this to deep-copy reference-type fields. If not implemented, a shallow copy (default struct assignment) is used.

Usage:

csharp
struct Inventory : IComponent, IAutoCopy<Inventory> {
    public List<int> Items;
    public void AutoCopy(ref Inventory c) {
        c.Items = c.Items != null ? new List<int>(c.Items) : null;
    }
}
csharp
public interface IAutoCopy<T> where T : struct

Type Parameters ​

T

Methods ​

AutoCopy(ref T) ​

Fix up component, a shallow copy of the source, before it is stored on the destination entity. Invoked on a default instance, so act on the parameter, not on this.

csharp
void AutoCopy(ref T component)

Parameters ​

component T