ECS confusion

Hi guys. In the last few weeks, I read a lot about ECS. Also, I started to use artemis-odb in my engine which was previously used a Unity-like game loop, where every GameObject might have onUpdate, onFrameStart, etc.

The confusion is this. Let’s say, if I have 3-4 entities, all have a MeshRenderer component, which contains the material and the mesh. In a MeshRendererSystem, I process those entities, add/update all of them into a batch and when all are processed, I do the render passes using the batches. That’s pretty mutch clear, I have entities with one component, and one system process them, then a separated logic uses the systems outcome.

But in other cases, I’m not sure, what to do. Eg.:
I have

  • a CursorEntity
  • a CursorScreenPositionComponent
  • a CursorPositionSystem

The component is attached to the entity, the system updates the component’s data, which is the cursor position on the screen. But where should I update the cursor (an image) position itself? So after a frame, I have an entity with an up2date component (thanks to the system), but what to do next?

Currently, I solve this that ECS systems run first in the gameloop, and after that, I run updater components that uses the updated entities.
I might miss something very basic stuff, so if you can recommend a great article or explain what did I miss, I would be so happy :slight_smile:

If you only need the CursorScreenPositionComponent to store a value that is used to calculate another value, why not skip that and set the world position directly in the cursorSystem?

Your cursor could be built like this:

  • positionComponent, generic world position component, also used by other entities
  • spriteComponent, generic sprite component, also used by other entities
  • cursorComponent, marks it as a cursor, contains only exclusively cursor-specific data or maybe even no data at all

There could be a cursorPositionSystem that takes the mouses screen-position from your game engine, calculates the world-position from that and sets the world-position of all entities with a cursorComponent and a positionComponent. That should happen before your sprite-render-system is invoked.

Components need to be as atomic as practically possible. The only difference between your cursor and any other 2d gameobject is that the cursor gets it’s position set to where the mouse points. After that it just get’s processed (drawn) together with the other 2d entities.

thx! Thats make sense. Tried it and looks kinda OK :slight_smile: