A Component is a structure of related data.

using Encompass;
using System.Numerics;

public struct VelocityComponent {

    public Vector2 Velocity { get; }

    public VelocityComponent(Vector2 velocity)
        Velocity = velocity;

Components are attached to Entities with the SetComponent method.

using Encompass;


var worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity();
worldBuilder.SetComponent(entity, new VelocityComponent(Vector2.One));

SetComponent can also be used from within an Engine. We will talk more about this later.

Components are always structs, meaning they follow value-type semantics. If you are used to working with classes you might find this confusing. One major point of difference is that value types are copied rather that passed by reference by default.

You can read more about value types here:

If you use them idiomatically, you don’t have to worry about them creating garbage collection pressure, so this is a big win for performance when working in C#.

Components should never reference other Components directly. This breaks the principle of loose coupling. You will regret it if you do this.