Nano ECS by SinyavtsevIlya - 1


c#-Unity ECS framework

Unknown VersionOtherUpdated 71 days 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)


The projects below made with Unity and NanoECS:

Save The Earth Hyper Race 3D Knife Away

First look

Entity creation

	// Create a new entity
        var player = contexts.Core.CreateEntity()	



        // Get entities with "position" and "view" components and without "movable" component
        CoreGroup group = contexts.Core.GetGroup()


        // handle filtered entities
	foreach (e in group) 



	// Get all entities with "speed" and "position" *only* when the position value is changed
        CoreCollector collector = contexts.Core.GetGroup()


	// handle these entities
	foreach (e in collector) 
		Print("My position has changed! : {0}", e.Position.Value);
	// and clear the collector when done

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.


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

How to use generator?

  • Go to Packages -> NanoECS -> Generator and run NanoEcsGenerator
  • Insure that you have a folder named Components somewhere inside your Assets folder
  • Create new component there, for example:
class Score
    int value;

Generator will automatically detect changes and create API fow you. You dont need to leave your IDE, just keep writing your code.

A few tips:

  • yes, you dont need to write “public” access modifier. It’s just a “blueprint” for a real component.
  • use camelCase for fields (real property will be PascalCased)
  • Fieldless components (e.g. class Movable { }) looks this way in the result: entity.IsMovable = true
  • you can use namespaces
  • you can use different contexts by adding a corresponding attribute(s). If you don’t specify any context at all, the first one from NanoECS settings will be chosen.

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