Skip to content
Jeff Campbell edited this page Jan 13, 2021 · 9 revisions

Overview

In this tutorial, we will walk through the basic workflow steps of EntitasRedux to include:

  • Implementing one or more Components.
  • Using code generation to populate our Context with the new Components.
  • Creating a System and a Controller class.
  • Create and destroy an Entity

Requirements

  • If this is your first time using an ECS framework, it may be helpful to read ECS Basics.
  • Entitas-Redux and Genesis are installed for your project
  • Genesis is configured for your project

Creating Components

A component defines a piece of data associated with an entity. A component is implemented as a plain-old CSharp object (POCO) that implement IComponent, has a default empty constructor, and exposes its data as public fields. This enables EntitasRedux during code generation to scaffold it such that code is generated for the Context and Entity it's associated with, enables internal pooling for component instances, etc...

As an example of a type of data a component might represent, we may want to be able to associate a 2D position with an entity. To create a component for this purpose, create a new file called PositionComponent and add the contents below.

public class PositionComponent :  IComponent
{
    public int x;
    public int y;
}

This component will be associated with the default or first defined context in the GenesisSettings asset when code-generation takes place. If we wanted to associate this component with a specific Context, we could add it's attribute to the component as well. This would result in that component during code-generation being associated only with that Context. As a general rule, it is a best-practice for design to only associate components with a Context where they relate to the intent of the simulation space it represents and are expected to be used on its entities.

[Game]
public class PositionComponent :  IComponent
{
    public int x;
    public int y;
}

Now after code-generation takes place this PositionComponent will only be associated with entities on the GameContext. Pressing CTRL + Shift + G on Windows or CMD + Shift + G on macOS to execute a code-generation run will propagate this component through the GameContext, creating additional entity APIs for adding, getting, replacing, and removing the PositionComponent.

Creating Systems

A system represents a specific stateless mechanical behaviour of zero or more entities in a given Context. An implementation of a system is typically done by implementing one or more system interfaces depending on the frequency or type of logic desired. This enables a developer to decide the type of object a system should be, whether that be a plain-old CSharp object (POCO), MonoBehaviour, or ScriptableObject.

  • IInitializeSystem => A system that executes setup logic prior to having other potential system methods executed.
  • ITearDownSystem => A system that executes logic one when a system is in the process of shutting down.
  • IFixedUpdateSystem => A system that executes one or more times based on the number of times the Unity update method FixedUpdate.
  • IUpdateSystem => A system that executes once per render frame based on the Unity Update method.
  • ILateUpdateSystem => A system that executes once per render frame based on the Unity LateUpdate method.
  • ICleanupSystem => A system that executes once per render frame after all ILateUpdateSystem instances have executed.

TODO System Code Example

Configuring Systems

TODO

Creating and Destroying Entities

TODO