#ECS discussion
1 messages Β· Page 1 of 1 (latest)
scriptableobject
Although it's my first experience with unity, I'm quite happy that I could translate the typical MVC architecture into this.
SOs store the base stats, and a regular object stores additional dynamic stats. All dynamic stats are observable for changes.
Usually the player would hold all their values directly as a list of components, you have systems running in the background that can manipulate those components and depending on your architecture the system changes things directly on your player or you fire an event and your player make the change themself
Ill make a broader example
I for example have:
- SO stats on maxSpeed
- regular object on curSpeed
- controller listening to the InputManager and updating the curSpeed
- view updating the sprite on the screen by listening to changes on curSpeed
class Entity (Player)
Component: Position
Component: Velocity
If event pattern: Event Listener: Position Change - [transform.position = Position]
class MovementSystem (Executed each frame)
Collect: Get all entites with a Position and a Velocity > 0
Execute: On all collected entites do [Position = Position + Velocity], also fire an event to the changed Entity that it has been changed
If no event pattern: Change transform.position of all entities that were updated
That way you could reuse the movement system on lets say a monster
just slap a position + velocity on them
and they move
In your example, don't you mix control (e.g., how to move the player) with visual (how to represent the updated position)?
You have a seperate InputSystem that would change the velocity
maybe on an entity that you filter out by having a component of "IsPlayer"
btw, Unity ECS uses no event pattern, atleast not built in
frameworks like Entitas have one built in
what I have is:
- InputBroker: listening to inputManager and offering game-events such as movement
- controllers to listen on game event actions and changing the models (SOs + live stats objects)
- views to update the game
It just feels strange that my enemies have 14+ scripts layered onto them for the different controls and views
for example, I originally had a different MVC chain for 'rotation' and another for 'aswd' movement. but I combined them .
The reason is that not all entities can rotate, so it would have made sense to keep it separate.
in the case of ECS your inputbroker would just be a system that changes components on the entites you want, not much of a change
changing a model could be as easy as changing the "model" component on an entity and reacting to the event of it
I need to look more into ECS to fully appreicate the difference to MVC. I coded 20 years of MVC and other standard patterns, so I'll need to do some research.
ECS is kind of a change of way from traditional programming, at first its confusing but as soon as you implement even small ECS patterns you will loose the confusion fast π
I use this atm: https://github.com/sschmid/Entitas
Its not as convoluted as DOTS/UnityECS but also not as performant
does the wikipedia page do thECS justice? https://en.wikipedia.org/wiki/Entity_component_system
Entity component system (ECS) is a software architectural pattern mostly used in video game development for the representation of game world objects. An ECS comprises entities composed from components of data, with systems which operate on entities' components.
ECS follows the principle of composition over inheritance, meaning that every entity ...
its very shallow but yes its a start π
Great. will look into entitas. Thanks!!
Just be aware that while coding with entitas is easy, you need to run a 3rd party code generator
I am not fully sure how experienced you are but it might be worth a shot to start with the Unity solution
Is there a good code template plugin for visual studio?
cause lets say you look for a job sometime in the future, nobody will know what entitas is π
oh i mean code generator, not templates
the event system behind entitas is auto-generated code
I know. that's why I ask for code templates, not a type templates
need to look for one.
I'll not look for a job in the future, so it's ok π
Put that in the main directory of the project and replace the name of the DotSettings file with your project name
dont know if visual studio can work with it though
Thanks. Will look for a VS code code template generator.
What I see (without audio) is that it is like tuple-space programming. You essentially create all these event tuples (=entities) and then some processor element consumes the tuples and updates the game state.
the entities (= mostly represented as gameobjects, but not required) would be the consumer and value (component) holder, the event pattern in ECS is not really part of base ecs