ECS architecture

Started by
30 comments, last by Tanzan 2 years, 11 months ago

Hello fellow developers i am currently developing a game on the ecs architecture and it works out fine.

The plumbing was terrible i must say but now it starts to get fruitful…

But i have a dilemma that i want your opinion on (i assume you know about ecs)

Imaging we have a hero which can move has health etc

so the movesystem handles all entities which has a move component with a move vector etc

now when the entity can't move anymore because of freeze spell or unconscious, death etc we can handle it two ways 1) we temporally ‘block’ the movement with the reason so we keep the move component with a boolean or so…i really don't like this option because the component manager of move has an ‘illegal’ component and in the end then all entities will have all components and it destroys the ecs architecture (i think) 2) we remove the movement component temporally until it needs to get back…healed, spell wears off etc…this is my favourite option because it respects the ecs and will work just fine. problem with this is how to get the move component back? who will be responsible for it ? and which will we add ? walk or was he flying ?

i wrote this right away while i was thinking about it, hope it makes sense ! ;-)

so what is your opinion about it ? i am curious.

Advertisement

Seems to me that in most cases velocity should still be used as normal, it can just become zero, and prevent further input from adding to it (and the stuff for handling character movement, could reasonably also access some spell status etc. components)? Then all the physics maths should just work out by itself.

And potentially in some cases depending on design you still want gravity, momentum to apply so a frozen/dead object might still move a bit.

Hi SyncViews,

thx for your reply :-)

Don't you think that that is the same solution as using a boolean in the move struct ? or at an extra component ‘blocked’. i mean the playercontroller adds velocity and a direction vector (all then not calculated). But then another ‘environment’ system (through component(s)) will set it to zero or add the blocked component. but in that way the move component stays connected to the entity.

Don't get me wrong that solution will work perfectly but for me it feels strange that entities keep components which are deactivated

again thx for thoughts!

I do it the same way - my Movement-component has a “paused” bool which allows me to halt en entity right where it is, and resume later. I don't think there is anything strange about it - no matter what the context, entity/game-object systems will probably always end up needing different mechanisms for handling subsystems like movement. Detaching the component for example is not valid for that use-case, since you need to retain the values (speed, etc…). Simply disabling it (if you have a general “disabled” state for your components) might be another solution, but might also not be applicable for that use-case (depening on how you treat “disabled" components; in my system a disabled component is virtually non-existant until re-enabled or explicitely requested). So yeah, I think having some sort of boolean to toggle this is perfectly normal.

@Juliean Hi Juliean, thx as well to think with me :-)

i agree that we need some control of course, but worst case will be that every entity ends up with almost every component which will be toggled on pause.

It feels a bit then like the OO method where we would create millions of isPickupable, isMoveable, isEquipable etc etc

i think that the power of ecs is that we just have a placeholder (entityid) and by adding components to them (dynamically) we add or remove members and so functionality (through the systems) to them.

again guys thx for thinking with me

Tanzan said:
i think that the power of ecs is that we just have a placeholder (entityid) and by adding components to them (dynamically) we add or remove members and so functionality (through the systems) to them. again guys thx for thinking with me,

In truth, I'm not using the ability to dynamically attach/remove components all the much anymore. For me the power of ECS lies in being able to develop features in isolation without running into the problems that rigid inheritance could lead to. For me, having a “move” component on an entity mean “this entity has the ability to move”. Whether the entity moves at that point in time is up to the component. If an entity becomes unmoveable for a large period of time or permanently, I detach the component or deactivate it, but if say my cutscene pauses the movement of my player-avatar, I simply “pause” the movement and animation. There are certainly up or downsides to eigther approaches, but you shouldn't be afraid to keep a simple problem like “I want to pause movement” simple and not overcomplicate it out of fear or just to comply with a purist-version of a pattern ?

@Juliean out of fear or just to comply with a purist-version of a pattern ?

So true ! ?

I am not at all a purist in that context its just that i wonder how to pro's do it….

The way how you describe your solution looks a lot like component based developing (which again is nothing wrong with) and not ecs

regards,

Tanzan said:
i agree that we need some control of course, but worst case will be that every entity ends up with almost every component which will be toggled on pause.

Oh pause I approached differently, since it pauses all game entities I just stopped most of the update stuff executing (basically skip the entire fixed step update, except input which feeds into the ui)

Tanzan said:
The way how you describe your solution looks a lot like component based developing (which again is nothing wrong with) and not ecs

Well, I'm pretty much using a hybrid-approach at this point, but I'm still using an ECS in the sense that components are mostly data (and very easy to copy/pooled), and logic is handled by systems operating on a bunch of components. I dropped the messaging-part though and now mostly call methods on systems to implement specific logic, and do some other things that go against the pure “ECS” idea. But I'm still much closer to ECS then unitys “component based” approach.

@SyncViews :-0 with pause i didn't mean literally pause but more that a component is not active for a while….

so for example if the hero would be glowing because of a powerup its really simple because after the powerup is done we can just destroy it…but in the context of flying or walking you need it to add it later again or disable it for a period as i discussed with Juliean

This topic is closed to new replies.

Advertisement