Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by GeorgeDoodlebug · Jan 09, 2020 at 10:11 PM · dotsarchitecturestate machine

ECS architecture & the state machine

I've recently been learning ECS and getting my head around DoD methodology, one question I have is around a State Machine replacement.


Imagine I have a realtime hack 'n' slash with a series of AI-driven monsters all running around independently. Now imagine the player opens up an inventory - with the desired effect of pausing the monsters behaviour. How would one architect this in ECS?


Do we give the monsters behaviour component a "paused" attribute and iterate through all of the monsters in the game setting it? Or...?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by RendrWyre · Jan 09, 2020 at 10:38 PM

@GeorgeDoodlebug You might want to do your own research because I might have misunderstood some of the ECS stuff..... but, AFAIK;


Archetypes are used to group entities that share the same components. Unity does this automatically (and at runtime) by grouping entities with the same components into an archetype. So, for example:

 Fish Archetype
 - Renderer Component
 - Mesh Component
 - Fish Health Component
 - Pause Component

 Vampire Archetype
 - Renderer Component
 - Mesh Component
 - Vampire Health Component
 - Pause Component


Although they are different archetypes they share similar components - namely a "pause" component. Now, this component should only hold the pure data needed to pause the monster. For example, an isPaused boolean or something. You might have a Pause Monster System that actually handles the pausing.


Now, onto the core of ECS... iteration. The "Pause Monster System" would iterate through each entity that has a "Pause Component" and write to that component (ie - set isPaused to true). It's basically like saying "find all of the entities with a Pause Component and then do something".

Unity has been publishing a lot of ECS/DOTS stuff from copenhagen 2019. Their Pong video (https://www.youtube.com/watch?v=a9AUXNFBWt4) is a good place to start if you're still struggling with the theory/how it works.


just as further clarification


  • Entities are like gameobjects. They represent "things" in your scene.

  • Components hold pure data.

  • Systems perform some kind of action on component data. For example, writing a new movement speed to an entity's movement component. In this case, a Movement System would write to a Movement Component of a single or multiple Entities.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by ben-rasooli · Aug 12, 2021 at 01:26 AM

The other two answers are right. If you wanna do it in a more structured and manageable way, you can read my recent article that is designed for your exact scenario. In short, you put your systems in a ComponentSystemGroup and then control their execution there.

alt text alt text


1-dr6rose4quhqconawctojq.png (206.5 kB)
1-aatxur9btcs9e3g3cz5onq.png (62.7 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by CaseyHofland · Jul 21, 2020 at 11:01 AM

One approach is to disable every system that is doing runtime stuff (or only movement stuff if you're lazy like me)

 private StepPhysicsWorld stepPhysicsWorld;
 private IncreaseVelocityOverTimeSystem increaseVelocityOverTimeSystem;
 
 protected override void OnCreate()
 {
     stepPhysicsWorld = World.GetOrCreateSystem<StepPhysicsWorld>();
     increaseVelocityOverTimeSystem = World.GetOrCreateSystem<IncreaseVelocityOverTimeSystem>();
 }
 
 protected override void OnUpdate() // From SystemBase
 {
     if(Input.GetKeyDown(KeyCode.P))
     {
         stepPhysicsWorld.Enabled = !stepPhysicsWorld.Enabled;
         increaseVelocityOverTimeSystem.Enabled = !increaseVelocityOverTimeSystem.Enabled;
     }
 }

But I concur, it is not ideal and if there is a better way I'd gladly hear.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by andrew-lukasik · Jul 21, 2020 at 01:04 PM

Paused is a game UI state and not a monster state - as opposed to freezed, petrified or unconscious). So it doesn't belong to IComponentData.


What you can do instead is to make relevant systems stop scheduling jobs while game is paused. This would probably include systems such as: monster locomotion, monster animation, decision making, decision execution (attacking, working etc) and also those changing values over time (health, hunger etc)


 public class MyPausableSystem : SystemBase {
 protected override void OnUpdate ()
 {
     if( gameUiStateSource.isPaused ) return;
     
     job1.Schedule();
     job2.Schedule();
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

121 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is it necessary to build my iphone app with armv7 architecture? 1 Answer

How to I get a reflection on the floor and on other objects ? 0 Answers

Undefined symbols for architecture armv7 0 Answers

Architectural Viz - Steps To Achieve The Grand Designs "Animation Simulation" 2 Answers

Clean architecture or ECS Architecture or both ? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges