Hi, it’s me and my board game again.
I’m looking for tips on the separation of behaviour and rendering in the ECS world. All of my game logic so far is pure data, and now i’m looking at ways to elegantly display that data without having to change the game logic.
In the old OOP world of Unity’s past, i’ve kept my game logic model in a separate out-of-unity dll, and had the in-unity display logic listen to events fired by the model, updating themselves accordingly.
However, In ECS, where events are really just short-lived components, this solution isn’t really possible without the model knowing about View entities and adding components to them.
I could attach rendering components the existing entities (Transform, Mesh components, etc), and systems that update the them (e.g. when a piece is moved on the board, LocationViewSystem update it’s Transform based on its in data board Location.). However, this doesn’t always work well,
One simple example: i’m looking at the age old problem of displaying corpses - in the game logic, a piece that is “taken” has it’s entity destroyed, but I still need to show the piece being destroyed visually, I don’t want the game logic to “wait” for the death animation, as that is creating a dependency on the view logic.
So far, I’ve come up with a few possible solutions:
-
Create Event Entities, emitted by the model with data about the model entities that fired them. The view can define systems that iterate over these events and map those to View entities.
-
Adapt the Model to support joint model-view entities - specifically, don’t destroy Piece entities when they are taken, but instead add or remove components to stop those entities from being processed by systems that act on Living entities. For example: by adding a
Destroyed
component andSubtractiveComponent<Destroyed>
properties in system groups. -
The concept of having separate Worlds for logic and rendering is something that is mentioned briefly in the documentation, but i’m not sure what that looks like structurally.
Any wisdom from the ECS vets here on achieving this separation?