Apologies if this is the wrong space for this question, and if it is a common one. Tell me, and i won’t hesitate to take it down.
I have gotten the impression that the ecs is an incredibly powerful paradigm for creating games with massive amounts of characters working. But i have also gotten the impression that it is generally “the future”, meaning that with time, most games will be made with it.
Im puzzled by how fine control of characters etc. can be achieved with these systems, that aren’t directly coupled to a specific character.
Take dark souls as for an example. Attacking in said game, locks the player in an animation till it finishes, but the player can cancel the animation shortly before it finishes, by dodgerolling. This is just a tiny part of it’s nuances, but does not seem realistic at all to implement in an ecs environment.
So my question goes: is ecs not for all game genres? Or am i just not experienced enough with ecs to realize how it may be organized when the nuances are many.
Why not? You have a PlayerControlSystem that takes the state of the player (probably a component on the entity) and which buttons were pressed, then chooses how to react.
That’s sounds ridicoulously normal, i understood systems and components as very atomic pieces, but if making the player controller one single system really is “allowed”; then i guess im wrong.
I think this answers my question, I think i have to go experiment with it to really get it though. You have my thanks.
About being atomyc or not is up to your use case and, in some way, personal taste. There is nothing wrong in making bigger system that does the job for you and, when and if the time comes, break it down into smaller pieces.
I find fine control over things to be easier in ECS. With ECS, you have a lot more control over execution order (systems with explicit order vs events which trigger events which trigger events). The granularity of systems in ECS are completely personal preference. I am not aware of anything that would prevent you from getting the same performance in a mega system than multiple smaller systems assuming you wrote the megasystem with proper optimizations. Also, not everything has to be stored in the ECS data structure either. There are other data structures and logical structures that a system can use.
Short answer; yes you can do any type of game or logic in DOTS
You can think about it like this:
In OOP your character class would have a bunch of variables and an update loop, and each character gameObject instance has their own set of modified variables
In ECS your character components have the variables and the various character systems constitute the update loop, and each character entity instance has its own set of modified variables
In the end both paradigms give you roughly the same potential for doing stuff; it’s all just instances of things with variables on them**,** and update loops affecting those variables. They’re just organized/structured differently. Certain things can be more difficult to pull off with multithreading, but you are never obligated to make everything multithreaded either (and you would probably face even more difficulties if you were to try doing multithreaded code in a non-DOTS context).
Two big differences come to mind:
if you were used to doing a lot of delegates and coroutines stuff in monobehaviour, DOTS might take a bit of effort getting used to. However, all delegates/coroutines stuff can also be implemented alternatively with a simple update loop or an event system in DOTS
In DOTS there’s going to be a bunch of situations where you’ll probably feel like you’d want to have polymorphism/inheritance in order to implement something, but you can’t have that. Like an “Ability” system or an “Item” system for example. These cases can be solved elegantly but you just have to move away from the OOP mindset and instead enter the Composition mindset
For the dark souls attack > roll interrupt thing in DOTS, you could have:
Implementation
There’s an AttackInputJob that listens for the attack input button. If pressed:
tell the animator component on your character entity to start the attack animation
put your character controller in an “attack” state so you can’t move regularly during the attack
“turn on” whatever hit detection implementation you have on your sword entity
The DOTS animation system plays the animation and updates the bone poses
In the SwordHitDetectionJob, if your sword is in “detect hits” mode and detects a hit with an enemy:
get the health component on that entity and reduce its health
Spawn SFX/VFX entities at the hit position
In the RollInputJob, if roll input button is pressed:
tell the animator component on your character entity to force a transition to roll animation
tell your character controller to be in “roll” mode so it knows how movement in this mode should be handled
“turn off” hit detection on your sword
(I actually don’t know how animation works in DOTS because I’ve never tried the package, but I assume it would be something like this)