Skip to content

Generate your first component

Simon Schmid edited this page Jun 19, 2015 · 13 revisions

Generate your first component

Let's create our first custom component and let the Code Generator do its magic!

Step 1

Open the Entitas preferences and set the Generated Folder path where the Code Generator should save files.

Entitas.Unity.VisualDebugging-Preference

Step 2

Create a new class and implement IComponent

using Entitas;

public class PositionComponent : IComponent {
    public float x;
    public float y;
    public float z;
}

Step 3

Select Entitas/Generate

Entitas.Unity.CodeGenerator

Step 4

Have fun!

var pool = new Pool(ComponentIds.TotalComponents);
var e = pool.CreateEntity();

e.AddPosition(1f, 2f, 3f);
e.ReplacePosition(3f, 2f, 1f);
e.RemovePosition();

var posX = e.position.x;
var hasPosition = e.hasPosition;

For more code examples see Code Generator

Clone this wiki locally