Skip to content

4. Getting Started

Knowlife4 edited this page Mar 10, 2023 · 11 revisions

Creating Scripts

ECT has built in script templates to ease the creation of new entities or components.

Entity Scripts

  • Right-click in the Project View and navigate to ECT > C# Script > Entity.

    image

    Note: It is recommended to suffix the name of your entity script with Entity, for example PlayerEntity.

You have created an entity script, it's as easy as that.

using ECT;

public class PlayerEntity : ECTEntity<PlayerEntity>
{
    void Update() => UpdateSystems();
}

Note: Generated entity scripts execute in every frame, but this can be changed by calling UpdateSystems() from somewhere else.


Entity

Component Scripts

  • Right-click in the Project View and navigate to ECT > C# Script > Component.

    image

    Note: It is recommended to prefix the name of your component script with parent's name, for example a movement component for the PlayerEntity would be PlayerMovement.

  • Open the component script and replace PARENT with your parent's type.

    Ex. If the parent's type is PlayerEntity then you would replace PARENT with PlayerEntity.

You have created a component script, it's as easy as that.

using ECT;

public class PlayerMovement : PlayerEntity.Component
{
    [ComponentSystem]
    public class System : System<PlayerMovement>
    {
        protected override void OnUpdate()
        {

        }
    }
}

Note: The [ComponentSystem] attribute assigns a default system but if you want to have multiple systems you can override the GetSystem() method instead.


Component

The Editor Experience

There are a few ways to interact with ECT from the editor itself.

Creating a Component Instance

  • Right-click in the Project View and navigate to ECT > Component Wizard.

    image

  • Select your component via the Component Dropdown.

    image

  • Type the name of your component instance into the text box and press the Create button.

    image


Component

You have created a component instance, it's as easy as that.

Using Entities

  • Create or choose an object you would like to use as an entity.

    image

  • Drag and drop your Entity Script into the inspector and you will see the editor show up.

    image

You have created an entity instance, now let's add a component instance.

  • Press the "+" button at the bottom of the component list to add a component instance slot.

    image

  • Drag and drop a component instance into this slot to add it to the entity and you will see its data show in the editor.

    image

    Note: You can only add components made specifically for this entity, for example you can't add an EnemyEntity component to a PlayerEntity.

Component Scene References

  • If your component has a SceneReference they will show up at the bottom of the Entity Editor and you will need to populate them.

    image


Entity