Nano ECS by SinyavtsevIlya - 1


c#-Unity ECS framework

Unknown VersionOtherUpdated 1 day agoCreated on March 27th, 2019
Go to source



NanoECS - C#/Unity entity-component-system framework


  • Code Generation (provides a really clean API, reducing boiler-plate code)
  • Reactive Components (gives you the ability to change component values in a pure manner, still providing reactive groups-triggering)
  • Visual Debugging (you can create/change contexts, entities and components inside the editor (Optional))
  • Unique components (singleton-like accessing components via contexts)

First look

Entity creation

        var player = contexts.Game.CreateEntity()	



        GameGroup group = contexts.Game.GetGroup()


	foreach (e in group) 



        GameCollector collector = contexts.Game.GetGroup()


	foreach (e in collector) 
		Print("My position has changed! : {0}", e.Position.Value);

Accessing component values

example 1:

        e.Position.Value += e.Direction.Value.ToVector3() * e.Speed.Value * delta;

example 2:

        foreach (var player in defeatedPlayers)
            player.IsDestroyed = true;

            if (!player.IsAIDriven)
                    .IsGameOverRequest = true;

Visual Debugging

entity editor entity editor

  • Reactive editing support (modifiyng component values gives the same result as “in code”)
  • GameObject linking (jump from the entity to the view game object and vice versa)
  • Lists, custom types, enums, Unity Objects are supported
  • Natural auto-complete workflow for adding new components, Foldouts, Create/Destroy buttons
  • Doesn’t affect realease builds performance. (And can be disabled / enabled manually in the settings)


entity editor

  • Generation works without reflection, so you can generate even if your project doesn’t compile at all
  • Doesn’t requere any manual actions from user to trigger generation. Just write the code and see how the new API appears. (Optional)
  • Customizable generation snippets.

Reactive components

Here’s how it works - you only create a template (or blueprint) of a component that looks like this:

class Score
    int value;

The generator parses this class, and creates a completely new component, with reactive properties instead of fields:

public partial class ScoreComponent : ComponentEcs 
	int value;
	public System.Action<int, int>OnValueChange;

	public int Value 
		get {  return value; }
			if (this.value == value) return;
			var cached = this.value;
			this.value = value;
			if (_InternalOnValueChange != null) 
			if (OnValueChange != null) 
				OnValueChange(cached, value);

When changing the value property, related entity is added to all .OnScoreChange collectors.


The framework is inspired a lot by such projects as Entitas, Actors, LeoECS. I like Entitas so much, but I found it’s really tricky to write “Replace” and filter-methods every-time. So the goal was to reduce boiler-plate and keep performance as well.



How to install

  • Create a new Unity Project
  • Open the manifest.json file in the Packages folder inside of the Project
  • Add "com.nanory.nanoecs": "", next to "dependencies": {
  • Go to Packages -> NanoECS -> Install and import ProjectStructure.unitypackage

Still in progress

  • It’s a very early version of framework. So bear with me 😃
  • Performance is tested in the mobile project (middle tier) with a lot of AI, render stuff etc. and it shows ~60 fps. I’m going to optimize it further, but it’s good enough for most purposes.
  • If you find a bug, let me know:
Show all projects by SinyavtsevIlya