Search code examples
javaunity-game-enginecomponentsentitycomposition

Are Unity's "MonoBehaviour Components" equivalent to systems from the Entity-Component-System design pattern?


I am working on making a very simple 2D game engine, and I am in the process of redoing my entities to work somewhat like Unity's system. I have been doing research on how the Entity-Component-System design pattern (ECS) works, and I am beginning to understand it better.

As I understand, a component in ECS only holds data and is not capable of doing anything but retain that data. These components are then used by systems which are used to read and manipulate their data.

This led me to question is if the MonoBehaviour scripts that are attached to a GameObject in Unity are technically systems and not components as they are called in the Unity editor?

If I am mistaken, I think it would be helpful for me to analyze true implementations of ECS. I am coding in Java, so if anyone has any examples of an ECS system implemented in Java or C#, that would be great as most of the examples I have seen were in C++ which is a bit more difficult for me to understand.
Thanks!


Solution

  • Unity doesn't strictly work via an ECS, despite using the term "Component." A Unity component, in the form of a MonoBehaviour, can have both data and system logic. Unity will, in future versions, be rolling out an ECS model.

    If you'd like to use current Unity versions (2018.1 and below) and strictly adhere to an ECS methodology, I'd suggest looking into Entitas and their Unity Plugin. You can also choose to structure your code, assets, and scenes to conform to ECS principles but Entitas is very efficient and solves a lot of problems for you.