#ECS discussion

1 messages Β· Page 1 of 1 (latest)

orchid surge
#

what do you mean with SOs?

vale spear
#

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.

orchid surge
#

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

vale spear
#

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
orchid surge
#
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

vale spear
#

In your example, don't you mix control (e.g., how to move the player) with visual (how to represent the updated position)?

orchid surge
#

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

vale spear
#

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.

orchid surge
#

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

vale spear
#

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.

orchid surge
#

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 πŸ˜„

vale spear
#

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 ...

orchid surge
#

its very shallow but yes its a start πŸ˜„

vale spear
#

Great. will look into entitas. Thanks!!

orchid surge
#

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

vale spear
#

Is there a good code template plugin for visual studio?

orchid surge
#

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

vale spear
#

I know. that's why I ask for code templates, not a type templates

orchid surge
#

i would have templates for jetbrains type IDEs

#

dont think they work in vs

vale spear
#

need to look for one.

vale spear
orchid surge
#

dont know if visual studio can work with it though

vale spear
#

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.

orchid surge
#

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