Skip to main content
34 votes
Accepted

Improving an O(N^2) function (all entities iterating over all other entities)

I know you do not conceptualize this as collisions, however what you are doing is colliding a circle centered at the creature, with all food. You really do not want to check food that you know is ...
Theraot's user avatar
  • 28.3k
16 votes

Improving an O(N^2) function (all entities iterating over all other entities)

You should adopt a space partitioning algorithm like BVH to reduce complexity. To be specific to your case, you need to make a tree that consists of axis-aligned bounding boxes that contain food ...
Ocelot's user avatar
  • 1,433
8 votes
Accepted

Unity Hybrid ECS with "old way"

It is perfectly possible to mix both styles. The same GameObject can have some of its functionality implemented with the new ECS system and other functionality in classic MonoBehaviour events. What ...
Philipp's user avatar
  • 123k
7 votes

Should components in Entity Component System pattern have logic?

I was considering voting to close this question as opinion-based, but I think there are a couple of misunderstandings about Entity-Component Systems and Data-Oriented Design here that are worth ...
DMGregory's user avatar
  • 141k
5 votes
Accepted

Should entities auto-register to systems based on their component signature?

TL;DR Entities SHOULD NOT auto-register to systems based on component signatures; prefer instead to explicitly declare component sets/nodes to register your entities to systems that operate on ...
Danny Yaroslavski's user avatar
5 votes
Accepted

How to implement n-body in an Entity Component System

One nice thing about systems in an ECS architecture is that they don't all necessarily need to follow the same structure of ...
Philipp's user avatar
  • 123k
5 votes
Accepted

How does ECS handle systems which need to know more about the environment of the entities it processes?

My solution to this would be to create a component AITarget which marks an entity as something zombies are supposed to attack (like a player or a civilian). Now ...
Philipp's user avatar
  • 123k
4 votes
Accepted

ECS component dependencies / sharing and cache locality

Reducing cache misses doesn't need to mean getting rid of them entirely, so we do need to be wary of "making the perfect the enemy of the good enough" After all, the absolute worst performance your ...
DMGregory's user avatar
  • 141k
4 votes
Accepted

How "smart objects" are implemented and actually work?

Well, concerning "The Sims" article you are reffering to that actually could mean a lot of different things. But the core idea as I get it is that each object can expose a list of "...
pabdulin's user avatar
  • 2,710
3 votes
Accepted

Is there a "Least Terrible Method" for sharing Entities over Network?

Preface: I'm not familiar with Box2D, but these structures can be found in Boost Geometry (R-trees) if you are really interested, as well as other libraries: Premature Optimization (Don't Do it) ...
Krupip's user avatar
  • 1,811
3 votes
Accepted

Make the components of an ECS polymorphic

Both your possible solutions are unnecessarily complicated or brittle: generally, ill-advised. Polymorphism Your question title is Make the components of an ECS polymorphic but then you don't ...
Engineer's user avatar
  • 30.4k
3 votes
Accepted

Where is 'game logic' implemented in component based design?

Not everything in your game must be based on the ECS pattern you're using and the game logic might be a good candidate not to. It could be a global script. Or, as you mention, you can implement the ...
rickyviking's user avatar
3 votes

Integrating Unity physics with Entitas

I literally just started looking at Entitas last night so there may be better solutions, but you could do something like the following: Create a component to store the collisions ...
Mattia's user avatar
  • 408
3 votes
Accepted

Implementation details of Command Pattern in conjunction with Entity Component System

How do I populate the execute command if there isn't any logic that "belongs" to an entity? But there is a mechanism for applying logic to an entity: Systems. In ECS, Systems map behavior to ...
Mattia's user avatar
  • 408
3 votes

ECS in MMOs - How to handle IDs for different object types?

I would generally not put entity IDs and type IDs into the same number-space. That just leads to confusion about whether a specific ID refers to an entity type or an unique instance of that type. ...
Philipp's user avatar
  • 123k
3 votes

Improving an O(N^2) function (all entities iterating over all other entities)

While the space partition methods described indeed can reduce the time your main problem is not just the lookup. Its the sheer volume of lookups you make that makes your task slow. So your optimizing ...
joojaa's user avatar
  • 399
3 votes

User-friendly scripting when using an ECS?

ECS has its pros and cons. User-friendly scripting is not one of its pros. The problem ECS solves is the ability to have a large number of similar things in your game at the same time while ...
Evorlor's user avatar
  • 5,891
3 votes

User-friendly scripting when using an ECS?

You could create a system ScriptExecutionSystem which operates on all entities with a Script component. It obtains all components of the entity which could be useful to expose to the scripting system ...
Philipp's user avatar
  • 123k
3 votes
Accepted

Should fields in components in an ECS use polymorphism?

feels like I'm violating the ECS rule There is no ECS police that will come and put you in ECS Jail. This is your architecture, you set it up how it fits your needs. having any functionality in ...
Vaillancourt's user avatar
  • 16.4k
3 votes

Cannot decide between using a MessageBus and entities for events in my ECS game

My approach was to have a PhysicsSystem which works on entities that have a ColliderComponent/PhysicsComponent/TransformComponent...
nenchev's user avatar
  • 141
3 votes

How to Implement ECS Archetypes in C#?

Here is a sketch of how you can implement an archetype in C#: ...
DMGregory's user avatar
  • 141k
2 votes

How to handle Entity Initialisation and Destruction

This is one of the common problems with ECS architecture: Intersystem communication. There is no silver bullet solution, and research is ongoing, but common solutions are: Observer patterns. Any ...
Ian Young's user avatar
  • 2,694
2 votes

Entity Component System: system and components relation

My point is: if the Systems are the ones responsible for the actual game logic update (practically speaking, the game logic code is written inside the system), is there a 1:1 relation between ...
sebas's user avatar
  • 490
2 votes
Accepted

How does Ashley keep systems up-to-date with its entities?

There is no way this array can be mutated. Wrong. If you look at the source code of ImmutableArray you can see that one of the constructors takes an ...
Applekini's user avatar
  • 8,543
2 votes
Accepted

ECS - should everything be a system?

Yes, all game objects should be entities with an appropriate component set, and each component should have a system that controls it. The whole idea of ECS architecture is compartmentalisation of ...
Ian Young's user avatar
  • 2,694

Only top scored, non community-wiki answers of a minimum length are eligible