en:toolworks:docs:apparatus:ecs

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
en:toolworks:docs:apparatus:ecs [2021/04/08 11:03] vladiusen:toolworks:docs:apparatus:ecs [2021/12/03 20:28] vladius
Line 1: Line 1:
 ====== Introduction to ECS ====== ====== Introduction to ECS ======
  
-Talking about object-oriented programming (OOP), we consider our practical task as multiplicity of special abstract things. In terms of Unreal Engine these abstractions are mainly called Objectsor ''UObjects'' if we are talking about C++ coding. Furthermore we apply a common principle like an inheritance model upon them. We create some main abstraction layer called 'base class', define some properties (i.e. variables and functions) in it and then by deriving a new type from that class we create other abstractions which in turn get all the parental properties and also define their own additionaldistinctive ones. A quite popular example for that approach is a tree of animal inheritance, where a base class represents any animal existing, while the others (derived from the base one) represent some separate animal sorts and kinds:+===== OOP Quirks & Limitations ===== 
 + 
 +Prior to exploring the ECS main concepts, we should address the [[wp>Object-oriented_programming|object-oriented programming (OOP)]] pattern and some of the issues related to it. That's because the current state of Unreal Engine's user-level API is basically OOP-based. Even the actor's component model is somewhat limited and is mostly static in nature. It really shouldn't be confused with a data-oriented approach we're presenting you with. 
 + 
 +A large portion of C++ language is also OOP and it was one of the main reasons behind its original design. It seems like the general top-level UE's architecture was heavily based on C++ some featuresor at least was heavily inspired by them. That's quite logical if you think of it. In the end C++ is the main language behind the tech. The Unreal build toolset (UBT and UHT) is implemented in C# which is also an OOP language by the way. 
 + 
 +So, when we develop games (and software in general) the OOP-way, we usually decompose all of the available entities and concepts into the hierarchies of their corresponding types. In terms of Unreal Engine those are mainly called Objects (or ''[[ue>API/Runtime/CoreUObject/UObject/UObject|UObjects]]'' if we are talking about C++ coding part). We create hierarchies of classes that are all derived from a single root ''UObject'' ancestorEvery time we create a new Blueprint (or a C++ class) it basically derives from this root class
 + 
 +As the time goes we notice that our classes become more and more in common and begin to [[wp>Code_refactoring|refactor]] the codebase (or the Blueprint assets), while extracting those common facilities into some separate base classes. Those in turn become the ancestors and we derive certain types from themthat should share their functionality. 
 + 
 +A quite popular example for that approach is a tree of animal inheritance, where a root class represents basically any animal existing (something like ''UObject''), while others derived represent some separate animal sorts and kinds on their own:
  
 {{ :en:toolworks:docs:oop-example.jpg?nolink |}} {{ :en:toolworks:docs:oop-example.jpg?nolink |}}
  
-By altering the base class properties we also change the current state of the whole object of derived type. We can also use some "virtual" overridable methods to modify the behavior for the derived classes. The problem here is that game logic can become too scattered across those classes and layersessentially making those layers horizontal as opposed to vertical inheritance.+The descendant types inherit the properties of their respective base types, so by altering the base class properties we also change the current state of the objects, if they are of some derived descendant type. We can also introduce some [[wp>Virtual_function|"virtual"]] overridable methods to be able to modify their behavior in the derived classes. 
 + 
 +All of that functionality surely look quite useful and nice, isn't it? Well yes it is, until you have like 100 classes. The problem here is that your game logic becomes too scattered across the class-layers in the hierarchy. You tend to forget what is defined on what level, what is overridable and what's not. The amount of coupling between the entities becomes scary and error-prone. Your coding partners who wrote some aspect of the base classes, become the keepers of some "secret knowledge". The time of refactoring sky-rockets for this every-growing hierarchy. This "ceremonial" job becomes your job itself, but not the development of the final end-user features. Not a good thing at all, considering how limited the time and resources can be. 
 + 
 +===== ECS to The Rescues ===== 
 + 
 +A solution to this hassle could be an approach called [[wp>Entity_component_system|Entity–component–system (or ECS for short)]]. 
 + 
 +There are no hierarchies in terms of ECS, as every game object (i.e. //entity//) is basically flat in its nature. It consists of data-only parts called //components//. You can combine those arbitrary on per-entity basis.
  
-A solution to this game development problem could be an approach called [[wp>Entity_component_system|ECS]].+Want your RPG character become a poison damage dealer? Add a ''poisonous'' component to it and consider it done, as long as you also implement a //system// that actually solves the poison mechanic.
  
-Apparatus provides all of the basic ECS idioms and even moreTo be unambiguous (and self-sustained, actually) our framework uses different naming scheme as compared to the classic ECSHere is the list of analogous terms:+Systems are remote to the details they operate upon. That's also a feature of ECS. They are like distant code blocks that take certain details as their operands and evaluate certain resultSystems are run after other systems and together they form a complete pipeline of your game.
  
-^ ECS Term            ^ Apparatus Term  ^ +That's basically it. But how come such a useful concept is not implemented in Unreal Engine yet? Well, it actually is, take Niagara as an example. The rendering pipeline can also be considered a pipeline. In other words, that may be all sorts of specific data-driven approaches taken in Unreal Engine, but none of them are as general-purpose as its OOP nature. We provide such approach for any of the user-available side of the Engine!
-| Entity              | Subject         | +
-| Component           | Detail          | +
-| System              | Mechanic        | +
-| A group of Systems  | Mechanism       | +
-| Archetype           | Fingerprint     | +
-| Chunk               | Belt            |+
  
 +Make sure your read our [[en:toolworks:docs:apparatus:ecs-glossary|Apparatus to ECS Glossary]] to get to know our terminology.
  
 ==== About ECS+ ==== ==== About ECS+ ====
  • en/toolworks/docs/apparatus/ecs.txt
  • Last modified: 2021/12/18 15:19
  • by jispar