First Configurations ECS Unity Project

In this part of the tutorial i will describe what i had to configure in the project and what a created to have some components working in a simple system

First things first

The first thing you need to do it is, install the Entities Package in your project

Go to the menu Window->Package Manager
Search in the All tab and check if it has already been installed, othewise do that

Now make sure that the Scripting Runtime Version is .NET 4.x as described in the previous part of the tutorial

Creating Render Prototypes

As i cited in the previeous tutorial, i decided to create all the entities programaticaly, but thinking in a solution that i can easily try another models and materials, i chosed to use a gameobject to enable us to edit the Mesh Instance Renderer Component

As for the Mesh, you have to chose the inner object of your model, a mesh

As for the material, you must create a Material and an important thing that have to be changed it is enable gpu instancing

 

Decoupling with Factories

I decided to create Factories of archetypes and entities to decouple of the bootstrap creation.

The Archetype Factory is basicaly a simple Dictionary of archetypes by archetypeName

The Entity Factory is a Delegate Dictionary by entityName

Creation

private delegate Entity Delegate1();

private Dictionary<string, Delegate1> entities = new Dictionary<string, Delegate1>();

One of the methods

    private Entity CreatePlayer()
    {
        this._entityManager = World.Active.GetExistingManager<EntityManager>();

        var playerEntity = this._entityManager.CreateEntity(ArchetypeFactory.Instance.getArchetypeByName("player"));
        this._entityManager.SetSharedComponentData(playerEntity, GetLookFromPrototype("PlayerRenderPrototype"));

        return playerEntity;
    }

Method used to retrieve information from render prototypes

private static MeshInstanceRenderer GetLookFromPrototype(string protoName)
    {
        var proto = GameObject.Find(protoName);
        var result = proto.GetComponent<MeshInstanceRendererComponent>().Value;
        Object.Destroy(proto);
        return result;
    }

Interface method used by bootstrap

    public Entity createEntityByName(string entityName)
    {
        return (Entity)entities[entityName].DynamicInvoke(null);
    }

Next Steps

In the next tutorial i will discuss about how will i solve the fact that pure ecs does not deal with physics automaticaly yet