Skip to content

Singleton marker type component

Daan van Yperen edited this page Sep 29, 2015 · 1 revision

Singleton marker-type components

Sometimes it can be useful to assign tag-type components - components with no data other than belonging to an entity.

If the project is setup with the maven plugin or when using the CLI, the easiest way is using @PackedWeaver on a component with no fields, thereby ensuring there will only ever be one instance of the component.

@PackedWeaver
public class SingletonComponent extends Component {}

The above code is equivalent to:

public class SingletonComponent extends PackedComponent {

    @Override
    protected void forEntity(Entity e) {}

    @Override
    protected void ensureCapacity(int id) {}

    @Override
    protected void reset() {}
}
Clone this wiki locally