Skip to content

Entitas Blueprints

Simon Schmid edited this page Mar 31, 2020 · 2 revisions

Deprecation Notice

Blueprints are no longer supported or included with the most recent releases of Entitas (#380) and remain in a beta state that is not ready for production use. They currently use binary serialization as a proof-of-concept. Migrating existing binary blueprints to a new version of Entitas can be difficult. Alternative data formats like Json are easier to migrate (#267).


Blueprints for Entitas let you create preconfigured entities right in the Unity editor in a similar manner to Unity's own prefabs. You can add multiple components and set initial values. The goal of blueprint is to allow anyone on a team to create and configure entities without needing to write any code to do so.

BlueprintInspector

Current limitations:

This first implementation uses the C# BinaryFormatter to serialize Blueprints. Feel free to contribute other formatters like Json, Xml, Yaml, etc. You can read more about serialization to understand it's limitations https://msdn.microsoft.com/en-us/library/ms233843.aspx

Match-One with Blueprints

You can test blueprints on the blueprints branch of the Match-One example project:

https://github.com/sschmid/Match-One/tree/feature/blueprints

Follow these basic steps to get started with Blueprints for Entitas:

  • Copy Entitas into your project

  • Open Menu -> Entitas -> Preferences

    • set your paths
    • optionally add a custom contexts
    • hit Generate

Entitas-Preferences

  • Create some components and generate again
using Entitas;

[Core]
public class NameComponent : IComponent {
    public string value;
}

[Core]
public class AgeComponent : IComponent {
    public int value;
}
  • Create a new Blueprint and set it up

Entitas-Create-Blueprint

BlueprintInspector

  • Create a Blueprints object

Entitas-Create-Blueprints

  • Generate again

  • Create a GameController and put it on a GameObject

using UnityEngine;
using Entitas.Unity.Serialization.Blueprints;

public class GameController : MonoBehaviour {

    public Blueprints blueprints;

    void Start() {

        var context = Contexts.core;

        var max = context.CreateEntity()
                    .ApplyBlueprint(blueprints.Max);

        var jack = context.CreateEntity()
                    .ApplyBlueprint(blueprints.Jack);


        Debug.Log("max.name.value: " + max.name.value);
        Debug.Log("jack.name.value: " + jack.name.value);
    }
}

Drag and drop the Blueprints into the Blueprints slot

GameController-Setup

  • Enter play-mode

GameController-Console

Clone this wiki locally