Some ES design questions

Hi friends

Some design questions about ES using Zay-ES

Starting with noob one
In simple tutorials in zay-es github wiki (written by @ia97lies [Christian thanks for tutorial :grinning:]) , I can see there is no setter method for components to change fields value, instead new component was created and overwrote the existing component. Which can impact on GC. Any reason for this ?

next one
Systems contacting with each others
ex: System A wants to tell system B (position system) to change position of an entity

Can system A call method from B directly ? (Seems very bad also will couple systems to each other and also will prevent multi threading)

Does system A need to update position component on entity and system B will detect this change by checking position components on all entities in it’s infinite loop (It is not event driven but polling pattern)

Or I need to have an event driven messaging system so systems can register there and contact with sending messages and each system can listen to specific message types. So systems without knowing each other can contact with each other (Like using Gdx-AI Telegraph library)

What is your idea ?


System A can create a component eg SetPosition, which can be read by system B which will update the position.

But problem with this approach is, after system B updated position then System A needs to know that position is updated then decides to move spatial to new position. So problem is how A will know that position for that specific entity is updated ?
System A should continuously check position on all entities to see if position is changed or not and continuously checking is an overload and not Event Driven approach.

There are several fundamental misunderstandings here.

One system sets a new component on an entity. Other systems detect that the component has changed. This is one of the reasons components are immutable… you swap them out and then the ES knows that it is new… and your other systems can see that, too. (It also makes it all thread safe, by the way.)

You can set things on a component directly if you want to but then you have to manage your own polling, your own multithreading, etc… might as well just go back to crappy non-ES-code. (There are some extremely narrow use-cases where this sort of thing may be necessary but mostly just use the ES like it was meant to be used.)

The rest of your post I’m not sure about… generally one system sets a component and the rest use it. If you have multiple systems setting a component then something is wrong with the design, either the systems or the components.

1 Like

It might be helpful for you to look at a full game example maybe:

The code has been moved here now:


Okaaaaaaay got that , thanks for making it clear
one question, if instead of creating new component i just modify current one and reset it on entity, will ES yet know that it is changed ?
(the reason i want to modify instead on create new one is to prevent from garbage creation )

Why ??? :anguished:

I have pathfinding system and cinematic motion control (group control) system which both can set position component on my entity (but not in same time) is this really wrong ???

This is a false savings because of all of the other stuff going on in an ES. The garbage collector is extremely good at cleaning up short-lived objects. It’s pretty much free.


Isn’t that key?

1 Like

Thanks Paul
I got what i needed to get. :grinning:

More questions may come later on.

One more question came to me and it is how should i use JME’s built in controls in my ES.
So for example i have an AnimationSystem which is very simple for now and it plays animation on entities. It needs to access to AnimControl of each entity to be able to play animation on it.
So what is the best way to access it in AnimationSystem.

Approach one : Give a HashMap<EntityId,AnimControl> animControls to system’s constructor so it has access to all AnimControls or maybe give it HashMap<EntityId,Spatial> spatials; so system can access to any built in controls it needs.

Approach two : Make those controls available to system in form of Components. So for example i create a AnimationControlComponent which implements EntityComponent and make a field references to AnimControl then add this component to entity so my AnimationSystem can access to it. (This one seems to be a bad practice)

Approach three : Please suggest if you have better one

What about SpatialComponent so it has access to any built in controls. :chimpanzee_amused:

1 Like

Yes, this is better actually :slight_smile:

Components should not contain things that “DO” stuff. That’s absolutely totally wrong. Components are data only. Just data. No doers.

Most of your view level systems will already have some kind of map to track the view objects that they are creating. You can see this even in SiO2’s EntityContainer utility class. (which by the way is a super convenient way to manage this sort of thing).

That answer is closer to your Approach one.

1 Like

Thanks for making it 100 % clear.
I will keep my first approach then. going to look at your SiO2 example also.

You can see some examples of usage in the sim-eth-es project. Like here:

And here:

And here:

1 Like

Thanks Paul.

Hey Paul
Your code is really clean and good documented and easy to understand and a good place to learn. I do like how you are managing stuffs. :slight_smile:
Just wanted to thank you for sharing them.
I am having good times with Zay-ES.


Thanks. :slight_smile:

A noob question
Can i have empty components (have no fields) ? Is it OK with ES design ?

example : Adding empty Keyboard component to any entities which want to be notified when a key is pressed. Notification is done by adding KeyAction component which has info of pressed key to all entities which have Keyboard component .

Yes, it sometimes happens.

Seems like you are abusing the ES to do view/control (in the MVC sense) specific stuff in components. A KeyAction doesn’t seem like a game object attribute to me.

1 Like